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

Missing, malformed or inaccessible config file(s) cause code panics #5485

Open
nagisa opened this issue Nov 26, 2021 · 6 comments
Open

Missing, malformed or inaccessible config file(s) cause code panics #5485

nagisa opened this issue Nov 26, 2021 · 6 comments
Assignees
Labels
C-bug Category: This is a bug Groomed Node Node team P-low Priority: low T-node Team: issues relevant to the node experience team

Comments

@nagisa
Copy link
Collaborator

nagisa commented Nov 26, 2021

Describe the bug

Running neard commands with an absent configuration file will cause neard invocations to panic, rather than to print out an error message and terminate regularly.

For example:

1. ./target/release/neard view_state peers
Nov 26 17:56:58.036 INFO neard: Version: trunk, Build: crates-0.10.0-64-gdcab6f416-modified, Latest Protocol: 49
thread 'main' panicked at 'Could not open config file: ~/.near/config.json', nearcore/src/config.rs:469:33
stack backtrace:
0: rust_begin_unwind
at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/std/src/panicking.rs:517:5
1: core::panicking::panic_fmt
at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/core/src/panicking.rs:101:14
2: nearcore::config::Config::from_file::(file::)closure
3: nearcore::config::Config::from_file
4: nearcore::config::load_config_without_genesis_records
5: nearcore::config::load_config
6: state_viewer::cli::StateViewerSubCommand::run
7: neard::cli::NeardCmd::parse_and_run
note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.


Touching the config file causes a different, more opaque panic:

1.  mkdir ~/.near && touch ~/.near/config.json && ./target/release/neard view_state peers Nov 26 18:00:07.619 INFO neard: Version: trunk, Build: crates-0.10.0-64-gdcab6f416-modified, Latest Protocol: 49 thread 'main' panicked at 'Failed to deserialize config: Error("EOF while parsing a value", line: 1, column: 0)', nearcore/src/config.rs:502:39 stack backtrace: 0: rust_begin_unwind at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/std/src/panicking.rs:517:5 1: core::panicking::panic_fmt at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/core/src/panicking.rs:101:14 2: core::result::unwrap_failed at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/core/src/result.rs:1617:5 3: nearcore::config::Config::from_file 4: nearcore::config::load_config_without_genesis_records 5: nearcore::config::load_config 6: state_viewer::cli::StateViewerSubCommand::run 7: neard::cli::NeardCmd::parse_and_run note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

If the config file exists, but cannot be opened or read from for other reasons, the panics like those above will be presented.

_**Expected behavior**_ 

`neard` should print an error message rather than raise a panic. These are user errors, not inherent mistakes in the codebase. Additionally, my belief is that the error messages should attempt to retain the causal chain so that it is possible to present not just `failed to deserialize config` but also `could not obtain config from "~/.near/config.json"`.

_**Version (please complete the following information):**_ 

*   dcab6f416
*   1.56
*   local
@bowenwang1996 bowenwang1996 added C-bug Category: This is a bug T-node Team: issues relevant to the node experience team labels Nov 26, 2021
@marcelo-gonzalez
Copy link
Contributor

didn't realize that #5695 existed, but these two issues seem to be talking about pretty much the same thing? I'll just close this one in favor of tht one since there's more discussion over there.

@nagisa
Copy link
Collaborator Author

nagisa commented Jan 6, 2022

Your call. I think this issue is reasonably actionable whereas #5695 is pretty broad and its hard to tell if anybody fixing that issue will get around to fixing this one.

@marcelo-gonzalez
Copy link
Contributor

Your call. I think this issue is reasonably actionable whereas #5695 is pretty broad and its hard to tell if anybody fixing that issue will get around to fixing this one.

@nagisa hm yah that's true. I'll reopen then, since in any case I dont think there's that much left to do to resolve just this one. will send some PRs soon

@marcelo-gonzalez marcelo-gonzalez linked a pull request Feb 7, 2022 that will close this issue
marcelo-gonzalez added a commit that referenced this issue Apr 1, 2022
This cleans up a few more panics in favor of presenting a more user-friendly error when things go wrong.

Issue: #5485
@stale
Copy link

stale bot commented Apr 6, 2022

This issue has been automatically marked as stale because it has not had recent activity in the last 2 months.
It will be closed in 7 days if no further activity occurs.
Thank you for your contributions.

@stale stale bot added the S-stale label Apr 6, 2022
@bowenwang1996
Copy link
Collaborator

@marcelo-gonzalez is this fixed in #6053 ? If so please close the issue

@stale stale bot removed the S-stale label Apr 15, 2022
@marcelo-gonzalez
Copy link
Contributor

@marcelo-gonzalez is this fixed in #6053 ? If so please close the issue

no not quite. That PR cleans up a lot of it, but it actually still panics, since there's still an unwrap(). It's just that the unwrap() is higher up the stack now. Still needs another PR or two to call this closed

@exalate-issue-sync exalate-issue-sync bot added T-nodeX and removed T-node Team: issues relevant to the node experience team labels Jun 28, 2022
@matklad matklad added T-node Team: issues relevant to the node experience team and removed T-nodeX labels Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug Groomed Node Node team P-low Priority: low T-node Team: issues relevant to the node experience team
Projects
None yet
Development

No branches or pull requests

5 participants