Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error codes #457

Merged
merged 30 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
eadeff5
add some meaningless codes real quik
JakeDawkins Apr 15, 2021
1999bdc
rough explain command and md generation
JakeDawkins Apr 16, 2021
02a1db3
Update src/command/explain.rs
JakeDawkins Apr 21, 2021
001816c
add markdown formatting to code explanations
JakeDawkins Apr 26, 2021
1027b21
use strum to convert from str -> enum
JakeDawkins Apr 26, 2021
95b0a7c
lint
JakeDawkins Apr 26, 2021
0bddcbe
Merge branch 'main' into jake/error-codes-coding-errors-code
JakeDawkins Apr 26, 2021
6bf602d
allow uppercase acronyms for EALL
JakeDawkins Apr 26, 2021
9f3df62
remove code for adhoc error
JakeDawkins Apr 26, 2021
f42b2d9
Merge branch 'main' into jake/error-codes-coding-errors-code
JakeDawkins Apr 29, 2021
005f60e
remove md link replacing
JakeDawkins May 3, 2021
c3eec10
update string allocation
JakeDawkins May 3, 2021
d1c7f61
Merge branch 'jake/error-codes-coding-errors-code' of github.com:apol…
JakeDawkins May 3, 2021
2271d2e
first batch of error descriptions
JakeDawkins May 3, 2021
460e54a
update messages
JakeDawkins May 4, 2021
a1f8860
update error code descriptions
JakeDawkins May 4, 2021
45cd14b
build error reference in build.rs
JakeDawkins May 5, 2021
88aaa32
remove EALL
JakeDawkins May 5, 2021
2438982
lint
JakeDawkins May 5, 2021
65241bb
Merge branch 'main' into jake/error-codes-coding-errors-code
JakeDawkins May 5, 2021
eb97d02
update changelog
JakeDawkins May 5, 2021
b9e9f1a
remove unused error code
JakeDawkins May 6, 2021
e544da1
update error message
JakeDawkins May 6, 2021
d36fc59
update code numbers
JakeDawkins May 6, 2021
4c2694c
Merge branch 'main' into jake/error-codes-coding-errors-code
JakeDawkins May 6, 2021
2c7e8d6
add error code for composition failure
JakeDawkins May 6, 2021
8cbfe0a
update error docs
JakeDawkins May 6, 2021
662d1fb
Merge branch 'main' into jake/error-codes-coding-errors-code
lrlna May 10, 2021
62296a7
add E028
lrlna May 10, 2021
c93f47c
Create E028.md
lrlna May 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
[pull/484]: https://github.com/apollographql/rover/pull/484
[issue/169]: https://github.com/apollographql/rover/issues/169

- **`rover explain` command added - [JakeDawkins], [pull/457]**

When encountering most errors in Rover, there will be an error code in the format
`E###` printed along with the error description. Running `rover explain CODE`
will now print a more detailed description of the error along with any
resolution steps and relevant docs links.

[JakeDawkins]: https://github.com/JakeDawkins
[pull/457]: https://github.com/apollographql/rover/pull/457

## 🐛 Fixes
## 🛠 Maintenance

Expand Down
139 changes: 139 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ structopt = "0.3.21"
toml = "0.5"
tracing = "0.1.26"
url = "2.2.0"
termimad = "0.10.1"
crossterm = "0.19.0"
strum = "0.20.0"
strum_macros = "0.20.1"

[dev-dependencies]
assert_cmd = "1.0.1"
Expand Down
61 changes: 61 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ fn main() -> Result<()> {
cargo_warn("updating npm package.");
prep_npm(is_release_build)?;

cargo_warn("updating error reference docs");
build_error_code_reference()?;

cargo_warn("exiting build.rs");

Ok(())
Expand Down Expand Up @@ -266,3 +269,61 @@ fn process_command_output(output: &Output) -> Result<()> {
Ok(())
}
}

fn build_error_code_reference() -> Result<()> {
let docs_path = Utf8PathBuf::from("./docs/source/errors.md");
let codes_dir = Utf8PathBuf::from("./src/error/metadata/codes");
let codes = fs::read_dir(codes_dir)?;

let mut all_descriptions = String::new();

// filter out Errs and non-file entries in the `/codes` dir
let code_files = codes
.into_iter()
.filter_map(Result::ok)
.filter(|e| !e.file_type().unwrap().is_dir());
Comment on lines +283 to +284
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we maybe error here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely could 🤷‍♂️ Especially since this is at buildtime. I just left it as the simpler option in the meantime. Do you think I should change that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah since it's at build time i think maybe we should error here so we don't commit something that doesn't work, i imagine filtering out the errors could end up with some head scratches if something goes wrong

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to keep this as is for now and we can get it to error in an xtask refactor.


// sort the list of files alphabetically
let mut code_files: Vec<_> = code_files.collect();
code_files.sort_by_key(|f| f.path());

// for each code description, get the name of the code from the filename,
// and add it as a header. Then push the header and description to the
// all_descriptions string
for code in code_files {
let path = code.path();

let contents = fs::read_to_string(&path)?;
let code_name = path
.file_name()
.unwrap()
.to_string_lossy()
.replace(".md", "");

let description = format!("### {}\n\n{}\n\n", code_name, contents);

all_descriptions.push_str(&description);
}

let docs_content = fs::read_to_string(&docs_path)?;

// I can't get this to work with multiline matching for some reason
// let re = Regex::new("(?m)<!-- BUILD_CODES -->*.*").unwrap();
// docs_content.replace(replace_pattern, all_descriptions);
JakeDawkins marked this conversation as resolved.
Show resolved Hide resolved

// build up a new docs page with existing content line-by-line
// and then concat the loaded code descriptions after
let mut new_content = String::new();
for line in docs_content.lines() {
new_content.push_str(line);
new_content.push('\n');
if line.contains("<!-- BUILD_CODES -->") {
break;
}
}
new_content.push_str(&all_descriptions);

fs::write(&docs_path, new_content)?;

Ok(())
}
lrlna marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions docs/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {
],
'Base Commands': ['graphs'],
'Federation Commands': ['subgraphs', 'supergraphs'],
Reference: ['errors'],
},
},
},
Expand Down
Loading