squiggle/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res

41 lines
1.2 KiB
Plaintext
Raw Normal View History

2022-04-11 03:16:31 +00:00
@genType
2022-03-29 09:09:59 +00:00
type errorValue =
| REArrayIndexNotFound(string, int)
| REAssignmentExpected
| REExpressionExpected
2022-03-29 09:09:59 +00:00
| REFunctionExpected(string)
2022-03-30 09:06:30 +00:00
| REJavaScriptExn(option<string>, option<string>) // Javascript Exception
| REMacroNotFound(string)
2022-03-29 09:09:59 +00:00
| RERecordPropertyNotFound(string, string)
| RESymbolNotFound(string)
2022-04-05 20:02:06 +00:00
| RESyntaxError(string)
2022-03-29 09:09:59 +00:00
| RETodo(string) // To do
2022-03-30 09:45:30 +00:00
type t = errorValue
2022-04-11 06:16:29 +00:00
@genType
2022-03-30 10:53:36 +00:00
let errorToString = err =>
2022-03-29 09:09:59 +00:00
switch err {
| REArrayIndexNotFound(msg, index) => `${msg}: ${Js.String.make(index)}`
| REAssignmentExpected => "Assignment expected"
| REExpressionExpected => "Expression expected"
2022-03-29 09:09:59 +00:00
| REFunctionExpected(msg) => `Function expected: ${msg}`
2022-03-30 09:06:30 +00:00
| REJavaScriptExn(omsg, oname) => {
2022-03-29 09:09:59 +00:00
let answer = "JS Exception:"
let answer = switch oname {
| Some(name) => `${answer} ${name}`
| _ => answer
}
let answer = switch omsg {
| Some(msg) => `${answer}: ${msg}`
| _ => answer
}
answer
}
| REMacroNotFound(macro) => `Macro not found: ${macro}`
2022-03-29 09:09:59 +00:00
| RERecordPropertyNotFound(msg, index) => `${msg}: ${index}`
| RESymbolNotFound(symbolName) => `${symbolName} is not defined`
2022-04-05 20:02:06 +00:00
| RESyntaxError(desc) => `Syntax Error: ${desc}`
2022-03-29 09:09:59 +00:00
| RETodo(msg) => `TODO: ${msg}`
}