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

tweak error handling #490

Merged
merged 5 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
55 changes: 13 additions & 42 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"typescript"
],
"dependencies": {
"@ryanatkn/belt": "^0.24.9",
"@ryanatkn/belt": "^0.24.10",
"chokidar": "^3.6.0",
"dotenv": "^16.4.5",
"es-module-lexer": "^1.5.4",
Expand All @@ -69,7 +69,7 @@
"@changesets/changelog-git": "^0.2.0",
"@changesets/types": "^6.0.0",
"@ryanatkn/eslint-config": "^0.4.2",
"@ryanatkn/fuz": "^0.115.0",
"@ryanatkn/fuz": "^0.115.1",
"@ryanatkn/moss": "^0.8.0",
"@sveltejs/adapter-static": "^3.0.2",
"@sveltejs/kit": "^2.5.18",
Expand Down
5 changes: 3 additions & 2 deletions src/lib/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ and the rest of the args are forwarded to the task's `run` function.
*/

// handle uncaught errors
attach_process_error_handlers((err) =>
err?.constructor?.name === 'Task_Error' ? 'Task_Error' : null,
attach_process_error_handlers(
(err) => (err.constructor.name === 'Task_Error' ? 'Task_Error' : null),
(err) => (err.constructor.name === 'Silent_Error' ? '' : null),
);

await sveltekit_sync_if_obviously_needed();
Expand Down
6 changes: 3 additions & 3 deletions src/lib/invoke_task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {print_ms, print_timings} from '@ryanatkn/belt/print.js';
import {to_forwarded_args, type Args} from './args.js';
import {run_task} from './run_task.js';
import {to_input_path, Raw_Input_Path} from './input_path.js';
import {find_tasks, load_tasks} from './task.js';
import {find_tasks, load_tasks, Silent_Error} from './task.js';
import {load_gro_package_json} from './package_json.js';
import {log_tasks, log_error_reasons} from './task_logging.js';
import type {Gro_Config} from './gro_config.js';
Expand Down Expand Up @@ -69,7 +69,7 @@ export const invoke_task = async (
const found = find_tasks([input_path], task_root_dirs, config);
if (!found.ok) {
log_error_reasons(log, found.reasons);
process.exit(1);
throw new Silent_Error();
}

// Found a match either in the current working directory or Gro's directory.
Expand All @@ -80,7 +80,7 @@ export const invoke_task = async (
const loaded = await load_tasks(found_tasks);
if (!loaded.ok) {
log_error_reasons(log, loaded.reasons);
process.exit(1);
throw new Silent_Error();
}
const loaded_tasks = loaded.value;

Expand Down
5 changes: 3 additions & 2 deletions src/lib/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const package_json = {
'typescript',
],
dependencies: {
'@ryanatkn/belt': '^0.24.9',
'@ryanatkn/belt': '^0.24.10',
chokidar: '^3.6.0',
dotenv: '^16.4.5',
'es-module-lexer': '^1.5.4',
Expand All @@ -61,7 +61,7 @@ export const package_json = {
'@changesets/changelog-git': '^0.2.0',
'@changesets/types': '^6.0.0',
'@ryanatkn/eslint-config': '^0.4.2',
'@ryanatkn/fuz': '^0.115.0',
'@ryanatkn/fuz': '^0.115.1',
'@ryanatkn/moss': '^0.8.0',
'@sveltejs/adapter-static': '^3.0.2',
'@sveltejs/kit': '^2.5.18',
Expand Down Expand Up @@ -964,6 +964,7 @@ export const src_json = {
{name: 'is_task_path', kind: 'function'},
{name: 'to_task_name', kind: 'function'},
{name: 'Task_Error', kind: 'class'},
{name: 'Silent_Error', kind: 'class'},
{name: 'Found_Task', kind: 'type'},
{name: 'Found_Tasks', kind: 'type'},
{name: 'Find_Tasks_Result', kind: 'type'},
Expand Down
6 changes: 6 additions & 0 deletions src/lib/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export const to_task_name = (
*/
export class Task_Error extends Error {}

/**
* This is used to tell Gro to exit silently, usually still with with a non-zero exit code.
* Using it means error logging is handled by the code that threw it.
*/
export class Silent_Error extends Error {}

export interface Found_Task {
input_path: Input_Path;
id: Path_Id;
Expand Down
Loading