| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 50b7f84 commit b7bd84f
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1234,10 +1234,11 @@ assert.throws( | |||
| 1234 | 1234 | (err) => { | |
| 1235 | 1235 | assert(err instanceof Error); | |
| 1236 | 1236 | assert(/value/.test(err)); | |
| 1237 | - // Returning anything from validation functions besides `true` is not | ||
| 1238 | - // recommended. Doing so results in the caught error being thrown again. | ||
| 1239 | - // That is usually not the desired outcome. Throw an error about the | ||
| 1240 | - // specific validation that failed instead (as done in this example). | ||
| 1237 | + // Avoid returning anything from validation functions besides `true`. | ||
| 1238 | + // Otherwise, it's not clear what part of the validation failed. Instead, | ||
| 1239 | + // throw an error about the specific validation that failed (as done in this | ||
| 1240 | + // example) and add as much helpful debugging information to that error as | ||
| 1241 | + // possible. | ||
| 1241 | 1242 | return true; | |
| 1242 | 1243 | }, | |
| 1243 | 1244 | 'unexpected error' | |
@@ -1288,8 +1289,8 @@ assert.throws(throwingFirst, /Second$/); | |||
| 1288 | 1289 | // at throwingFirst (repl:2:9) | |
| 1289 | 1290 | ``` | |
| 1290 | 1291 | ||
| 1291 | - Due to the confusing notation, it is recommended not to use a string as the | ||
| 1292 | - second argument. This might lead to difficult-to-spot errors. | ||
| 1292 | + Due to the confusing error-prone notation, avoid a string as the second | ||
| 1293 | + argument. | ||
| 1293 | 1294 | ||
| 1294 | 1295 | [`Class`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes | |
| 1295 | 1296 | [`ERR_INVALID_RETURN_VALUE`]: errors.html#errors_err_invalid_return_value | |
| Back | FazBrowse Home | New Git URL |
0 commit comments