Skip to content
Open
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
10 changes: 6 additions & 4 deletions backend/src/BuiltinCliHost/Libs/Cli.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let executePM
match execResult with
| Ok dval -> return dval
| Error(rte, _cs) ->
let accountID = None
let accountID = Some exeState.program.canvasID
let! rteString = Exe.runtimeErrorToString accountID branchID exeState rte
match rteString with
| Ok rte ->
Expand Down Expand Up @@ -108,7 +108,7 @@ let parseCliScript
"Invalid error format from parseCliScript"
[ "dval", dval ]
| Error(rte, _cs) ->
let! rteString = Exe.runtimeErrorToString None branchID exeState rte
let! rteString = Exe.runtimeErrorToString accountID branchID exeState rte
match rteString with
| Ok errorDval ->
return
Expand Down Expand Up @@ -244,7 +244,8 @@ let fns : List<BuiltInFn> =
|> RT2DT.RuntimeError.toDT
|> resultError
| Error(e, callStack) ->
let! csString = Exe.callStackString exeState callStack
let! csString =
Exe.callStackString accountID branchID exeState callStack
print $"Error when executing Script. Call-stack:\n{csString}\n"
return e |> RT2DT.RuntimeError.toDT |> resultError
| Error e -> return e |> RT2DT.RuntimeError.toDT |> resultError
Expand Down Expand Up @@ -477,7 +478,8 @@ let fns : List<BuiltInFn> =
let asString = DvalReprDeveloper.toRepr result
return resultOk (DString asString)
| Error(e, callStack) ->
let! csString = Exe.callStackString exeState callStack
let! csString =
Exe.callStackString accountID branchID exeState callStack
print $"Error when executing expression. Call-stack:\n{csString}\n"
return e |> RT2DT.RuntimeError.toDT |> resultError
| Error e -> return e |> RT2DT.RuntimeError.toDT |> resultError
Expand Down
14 changes: 12 additions & 2 deletions backend/src/Cli/Cli.fs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,20 @@ let main (args : string[]) =
let state = state cliPackageManager

let errorCallStackStr =
(LibExecution.Execution.callStackString state callStack).Result
(LibExecution.Execution.callStackString
(Some state.program.canvasID)
None
state
callStack)
.Result

match
(LibExecution.Execution.runtimeErrorToString None None state rte).Result
(LibExecution.Execution.runtimeErrorToString
(Some state.program.canvasID)
None
state
rte)
.Result
with
| Ok(RT.DString s) ->
logError $"Encountered a Runtime Error:\n{s}\n\n{errorCallStackStr}\n "
Expand Down
22 changes: 18 additions & 4 deletions backend/src/LibCloudExecution/CloudExecution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ let createState
let epToString ep =
match ep with
| None -> Ply "None -- empty CallStack"
| Some ep -> Exe.executionPointToString state ep
| Some ep ->
Exe.executionPointToString (Some state.program.canvasID) None state ep

let! entrypoint = epToString (RT.CallStack.entrypoint callStack)
let! lastCalled = epToString (RT.CallStack.last callStack)
Expand Down Expand Up @@ -124,7 +125,8 @@ let executeHandler
HashSet.add h.tlid tracing.results.tlids
let! result = Exe.executeToplevel state h.tlid instrs

let callStackString = Exe.callStackString state
let callStackString =
Exe.callStackString (Some state.program.canvasID) None state

let error (msg : string) : RT.Dval =
let typeName = RT.FQTypeName.fqPackage PackageIDs.Type.Stdlib.Http.response
Expand All @@ -145,14 +147,26 @@ let executeHandler
| Error(originalRTE, originalCallStack) ->
let! originalCallStack = callStackString originalCallStack

match! Exe.runtimeErrorToString None None state originalRTE with
match!
Exe.runtimeErrorToString
(Some state.program.canvasID)
None
state
originalRTE
with
| Ok(RT.DString msg) ->
let msg = $"Error: {msg}\n\nSource: {originalCallStack}"
return error msg
| Ok result -> return result
| Error(firstErrorRTE, firstErrorCallStack) ->
let! firstErrorCallStack = callStackString firstErrorCallStack
match! Exe.runtimeErrorToString None None state firstErrorRTE with
match!
Exe.runtimeErrorToString
(Some state.program.canvasID)
None
state
firstErrorRTE
with
| Ok(RT.DString msg) ->
return
error (
Expand Down
16 changes: 13 additions & 3 deletions backend/src/LibExecution/Execution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ let runtimeErrorToString

// CLEANUP not ideal, but useful
let getPackageFnName
(accountID : Option<uuid>)
(branchID : Option<uuid>)
(state : RT.ExecutionState)
(id : RT.FQFnName.Package)
: Ply<string> =
Expand All @@ -171,8 +173,10 @@ let getPackageFnName
let typeName =
RT.FQTypeName.fqPackage
PackageIDs.Type.LanguageTools.ProgramTypes.FQFnName.fqFnName
let accountIDDval = accountID |> Option.map Dval.uuid |> Dval.option RT.KTUuid
let branchIDDval = branchID |> Option.map Dval.uuid |> Dval.option RT.KTUuid
let dval = RT.DEnum(typeName, typeName, [], "Package", [ RT.DUuid id ])
let args = NEList.singleton dval
let args = NEList.ofList accountIDDval [ branchIDDval; dval ]
let! result = executeFunction state fnName [] args
match result with
| Ok(RT.DString s) -> return s
Expand Down Expand Up @@ -225,6 +229,8 @@ let getPackageFnName


let executionPointToString
(accountID : Option<uuid>)
(branchID : Option<uuid>)
(state : RT.ExecutionState)
(ep : RT.ExecutionPoint)
: Ply<string> =
Expand All @@ -243,7 +249,7 @@ let executionPointToString
match ep with
| RT.Source -> return "Source"
| RT.Function(RT.FQFnName.Package id) ->
let! name = getPackageFnName state id
let! name = getPackageFnName accountID branchID state id
return $"Package Function {name}"
| RT.Function(RT.FQFnName.Builtin fnName) ->
return $"Builtin Function {fnName.name}" // TODO actually fetch the fn, etc
Expand All @@ -256,13 +262,17 @@ let executionPointToString
/// - consider accepting a VMState rather than the CallStack
/// - generally tidy the output here
let callStackString
(accountID : Option<uuid>)
(branchID : Option<uuid>)
(state : RT.ExecutionState)
(callStack : RT.CallStack)
: Ply<string> =
uply {
// First, convert all execution points to strings
let! stringParts =
Ply.List.mapSequentially (fun ep -> executionPointToString state ep) callStack
Ply.List.mapSequentially
(fun ep -> executionPointToString accountID branchID state ep)
callStack

// Group consecutive identical entries with counts
let rec groupConsecutive acc current count remaining =
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/TestUtils/TestUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ let unwrapExecutionResult
[]
(NEList.ofList branchID [ rte ])

let! cs = LibExecution.Execution.callStackString state callStack
let! cs = LibExecution.Execution.callStackString None None state callStack

match rteMessage with
| Ok(RT.DString msg) -> return RT.DString(msg + "\n" + cs)
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/Tests/LibExecution.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ let t
RT.FQFnName.fqPackage
PackageIDs.Fn.PrettyPrinter.RuntimeTypes.RuntimeError.toErrorMessage

let! _csString = Exe.callStackString state callStack
let! _csString = Exe.callStackString None None state callStack

let accountID = Dval.optionNone RT.KTUuid
let branchID = Dval.optionNone RT.KTUuid
Expand Down