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

Common.throw() Function #2941

Merged
merged 4 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-fireants-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@quri/squiggle-lang": patch
---

Added Common.throw
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,22 @@ export const library = [
),
],
}),
maker.make({
name: "throw",
description:
"Throws a fatal error. There is no way in the language to catch this error.",
definitions: [
makeDefinition(
[frOptional(frNamed("message", frString))],
frAny(),
([value]) => {
if (value) {
throw new Error(value);
} else {
throw new Error("Common.throw() was called");
}
}
),
],
}),
];
4 changes: 2 additions & 2 deletions packages/squiggle-lang/src/library/registry/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { library as booleanLibrary } from "../../fr/boolean.js";
import { library as builtinLibrary } from "../../fr/builtin.js";
import { library as commonLibrary } from "../../fr/common.js";
import { library as calculatorLibrary } from "../../fr/calculator.js";
import { library as dangerLibrary } from "../../fr/danger.js";
import { library as dateLibrary } from "../../fr/date.js";
Expand Down Expand Up @@ -54,7 +54,7 @@ const fnList: FRFunction[] = [
...unitsLibrary,
...calculatorLibrary,
...inputLibrary,
...builtinLibrary, // should go last, because has some catch-all functions
...commonLibrary, // should go last, because has some catch-all functions
];

export const registry = Registry.make(fnList);
Expand Down