mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
# What Add an ast-grep rule to use `bail!` rather than `Err(anyhow!(` in a return position. # Why This is slightly more compact, and allows us to port more code over to turbofmt/turbobail. Note: _this PR was previously merged into another branch due to a GH bug_
24 lines
697 B
YAML
24 lines
697 B
YAML
id: no-err-anyhow
|
|
valid:
|
|
- 'bail!("error message")'
|
|
- 'bail!("error: {}", msg)'
|
|
- 'Err(SomeOtherError::new("error"))'
|
|
- 'Err(err.into())'
|
|
- 'Err(anyhow!("error").context("context"))'
|
|
- 'Some(Err(anyhow!("wrapped in Some")))'
|
|
- 'Some(Err(anyhow::anyhow!("wrapped in Some")))'
|
|
- 'self.error = Err(anyhow::anyhow!("assigned to field"))'
|
|
- 'Err(anyhow::anyhow!("msg")).context("ctx")'
|
|
- |
|
|
let x = match blah {
|
|
1 => Err(anyhow!("foo")),
|
|
2 => Ok(()),
|
|
};
|
|
do_something();
|
|
return x;
|
|
invalid:
|
|
- 'Err(anyhow!("error message"))'
|
|
- 'Err(anyhow!("error: {}", msg))'
|
|
- 'Err(anyhow::anyhow!("error message"))'
|
|
- 'Err(anyhow::anyhow!("error: {}", msg))'
|