Skip to content
This repository was archived by the owner on May 23, 2024. It is now read-only.

Commit 0e7fc9c

Browse files
authored
Merge pull request #257 from Alexendoo/commit-message-null
Replace null bytes in commit message descriptions
2 parents 237dc62 + cb02b33 commit 0e7fc9c

File tree

9 files changed

+40
-33
lines changed

9 files changed

+40
-33
lines changed

.github/workflows/autofix.yml

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ jobs:
99
runs-on: ubuntu-latest
1010
if: github.repository == 'rust-lang/glacier'
1111

12+
env:
13+
RUST_LIB_BACKTRACE: 1
14+
1215
steps:
1316
- uses: actions/checkout@v1
1417

Cargo.lock

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2018"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10+
anyhow = "1.0.26"
1011
rayon = "1.2.0"
1112
tempfile = "3.1.0"
1213

autofix/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2018"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10+
anyhow = "1.0.26"
1011
glacier = { path = ".." }
1112
once_cell = "1.2.0"
1213
reqwest = "0.9.21"

autofix/src/fix.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::github::{self, pull_request, PullRequestOptions};
2+
use anyhow::{Context, Result};
23
use git2::{PushOptions, RemoteCallbacks, Repository, Tree};
34
use glacier::TestResult;
4-
use std::error::Error;
55
use std::fs::read_to_string;
66
use std::path::{Path, PathBuf};
77

@@ -14,7 +14,7 @@ struct Descriptions {
1414
pr_body: String,
1515
}
1616

17-
fn format_descriptions(test: &TestResult) -> Result<Descriptions, Box<dyn Error>> {
17+
fn format_descriptions(test: &TestResult) -> Result<Descriptions> {
1818
let title = test.title();
1919
let description = test.description().unwrap();
2020

@@ -44,18 +44,18 @@ fn new_path_bytes(old: &Path) -> Option<Vec<u8>> {
4444
Some(new.to_str()?.as_bytes().to_vec())
4545
}
4646

47-
fn move_to_fixed<'a>(repo: &'a Repository, test: &TestResult) -> Result<Tree<'a>, Box<dyn Error>> {
47+
fn move_to_fixed<'a>(repo: &'a Repository, test: &TestResult) -> Result<Tree<'a>> {
4848
let mut index = repo.index()?;
4949

5050
// Stage 0 = normal file, not part of a merge
5151
let mut entry = index
5252
.get_path(test.path(), 0)
53-
.ok_or_else(|| format!("not found in index: {}", test.path().display()))?;
53+
.with_context(|| format!("not found in index: {}", test.path().display()))?;
5454

5555
index.remove(test.path(), 0)?;
5656

5757
let new_path =
58-
new_path_bytes(test.path()).ok_or_else(|| format!("ICE has no filename: {:?}", test))?;
58+
new_path_bytes(test.path()).with_context(|| format!("ICE has no filename: {:?}", test))?;
5959

6060
entry.path = new_path;
6161

@@ -66,7 +66,7 @@ fn move_to_fixed<'a>(repo: &'a Repository, test: &TestResult) -> Result<Tree<'a>
6666
Ok(repo.find_tree(id)?)
6767
}
6868

69-
fn push(repo: &Repository, refspec: &str, config: &github::Config) -> Result<(), Box<dyn Error>> {
69+
fn push(repo: &Repository, refspec: &str, config: &github::Config) -> Result<()> {
7070
let mut callbacks = RemoteCallbacks::new();
7171

7272
callbacks.push_update_reference(|_ref, status| match status {
@@ -85,7 +85,7 @@ fn push(repo: &Repository, refspec: &str, config: &github::Config) -> Result<(),
8585
Ok(())
8686
}
8787

88-
pub(crate) fn fix(test: &TestResult, config: &github::Config) -> Result<(), Box<dyn Error>> {
88+
pub(crate) fn fix(test: &TestResult, config: &github::Config) -> Result<()> {
8989
let repo = Repository::open(".")?;
9090

9191
let path = test.path().display();

autofix/src/github.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use anyhow::Result;
12
use once_cell::sync::Lazy;
23
use reqwest::Client;
34
use serde::{Deserialize, Serialize};
4-
use std::env::{var, VarError};
5+
use std::env::var;
56

67
static CLIENT: Lazy<Client> = Lazy::new(Client::new);
78

@@ -11,7 +12,7 @@ pub(crate) struct Config {
1112
}
1213

1314
impl Config {
14-
pub(crate) fn from_env() -> Result<Self, VarError> {
15+
pub(crate) fn from_env() -> Result<Self> {
1516
Ok(Self {
1617
token: var("GITHUB_TOKEN")?,
1718
repo: var("GITHUB_REPOSITORY")?,
@@ -40,10 +41,7 @@ struct PullRequest {
4041
html_url: String,
4142
}
4243

43-
pub(crate) fn pull_request(
44-
config: &Config,
45-
options: &PullRequestOptions,
46-
) -> Result<String, reqwest::Error> {
44+
pub(crate) fn pull_request(config: &Config, options: &PullRequestOptions) -> Result<String> {
4745
let url = format!("https://api.github.com/repos/{}/pulls", config.repo);
4846

4947
let pr: PullRequest = CLIENT

autofix/src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
mod fix;
22
mod github;
33

4+
use anyhow::{Context, Result};
45
use fix::fix;
56
use glacier::rayon::prelude::*;
67
use glacier::{test_all, Outcome};
7-
use std::error::Error;
88

9-
fn main() -> Result<(), Box<dyn Error>> {
9+
fn main() -> Result<()> {
1010
let config = github::Config::from_env()?;
1111

1212
test_all()?
13-
.collect::<Result<Vec<_>, _>>()?
13+
.collect::<Result<Vec<_>>>()?
1414
.into_iter()
1515
.filter(|result| result.outcome() != Outcome::ICEd)
16-
.try_for_each(|result| fix(&result, &config))
16+
.try_for_each(|result| fix(&result, &config).context(result))
1717
}

src/lib.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use anyhow::{bail, Result};
12
use rayon::prelude::*;
2-
use std::error::Error;
33
use std::fmt;
44
use std::path::{Path, PathBuf};
55
use std::process::Command;
@@ -23,17 +23,17 @@ struct ICE {
2323
}
2424

2525
impl ICE {
26-
fn from_path(path: PathBuf) -> Result<Self, Box<dyn Error>> {
26+
fn from_path(path: PathBuf) -> Result<Self> {
2727
let mode = match path.extension().and_then(|e| e.to_str()) {
2828
Some("rs") => TestMode::SingleFile,
2929
Some("sh") => TestMode::ShellScript,
30-
_ => return Err(format!("unknown ICE test extension: {}", path.display()).into()),
30+
_ => bail!("unknown ICE test extension: {}", path.display()),
3131
};
3232

3333
Ok(Self { path, mode })
3434
}
3535

36-
fn test(self) -> Result<TestResult, Box<dyn Error>> {
36+
fn test(self) -> Result<TestResult> {
3737
let workdir = tempfile::tempdir()?;
3838
let output = match self.mode {
3939
TestMode::SingleFile => Command::new(RUSTC)
@@ -111,7 +111,7 @@ impl TestResult {
111111
out.push_str(self.stderr());
112112
out.push_str("==============");
113113

114-
Some(out)
114+
Some(out.replace('\0', "NUL"))
115115
} else {
116116
None
117117
}
@@ -148,7 +148,7 @@ impl fmt::Display for TestResult {
148148
}
149149
}
150150

151-
fn discover(dir: &str) -> Result<Vec<ICE>, Box<dyn Error>> {
151+
fn discover(dir: &str) -> Result<Vec<ICE>> {
152152
let mut ices = Vec::new();
153153
for entry in std::fs::read_dir(dir)? {
154154
let entry = entry?;
@@ -167,12 +167,8 @@ fn discover(dir: &str) -> Result<Vec<ICE>, Box<dyn Error>> {
167167
Ok(ices)
168168
}
169169

170-
pub fn test_all() -> Result<impl IndexedParallelIterator<Item = Result<TestResult, String>>, String>
171-
{
172-
let iter = discover(ICES_PATH)
173-
.map_err(|e| e.to_string())?
174-
.into_par_iter()
175-
.map(|ice| ice.test().map_err(|e| e.to_string()));
170+
pub fn test_all() -> Result<impl IndexedParallelIterator<Item = Result<TestResult>>> {
171+
let iter = discover(ICES_PATH)?.into_par_iter().map(|ice| ice.test());
176172

177173
Ok(iter)
178174
}

src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
use anyhow::{bail, Result};
12
use glacier::Outcome;
23
use rayon::prelude::*;
3-
use std::error::Error;
44

5-
fn main() -> Result<(), Box<dyn Error>> {
5+
fn main() -> Result<()> {
66
let failed = glacier::test_all()?
7-
.map(|res| -> Result<bool, String> {
7+
.map(|res| -> Result<bool> {
88
let result = res?;
99
println!("{}", result);
1010

@@ -13,7 +13,7 @@ fn main() -> Result<(), Box<dyn Error>> {
1313
.try_reduce(|| false, |a, b| Ok(a || b))?;
1414

1515
if failed {
16-
Err("some ICEs are now fixed!".into())
16+
bail!("some ICEs are now fixed!");
1717
} else {
1818
Ok(())
1919
}

0 commit comments

Comments
 (0)