script tool: Exception traceback
Posted: Wed Apr 15, 2020 6:13 am
Using JavaScript's
The
[I'm calling it primitive because the
I've witten a script that parses & formats this object into something readable (default
vs the usual from the debug console
or the Latest.log file
and that last is only with the developers release!
Of the 5 parameters to
The two optional ones deal with how much of the items in
The same example, now with
and
I won't bore you with examples of
If your function has properties, they are displayed exactly like parameters, but you can specify a different
There's a more complete explanation in the file itself. Just paste it into your script and you're good to go.
https://www.dropbox.com/s/cjldriko9aaq ... r.js?dl=0
try ... catch
statement, a primitive form of call stack traceback is possible.
Code: Select all
this._initOptions = function initOptions( oxp ) {
try {
registeredOxps[ oxp ] = ...
...
} catch( err ) {
log(this.name, ws._reportError( err, initOptions, [oxp, registeredOxps, decodedChoice], 1 ) );
if( debug ) throw err; // NB: not _initOptions
}
}
err
argument from catch
is an Error object with properties:message, fileName, lineNumber, stack & name
[I'm calling it primitive because the
stack
property is just one long string, so the function parameters cannot be evaluated. <sigh> We work with what we have.]I've witten a script that parses & formats this object into something readable (default
depth = 1
):
Code: Select all
function initOptions() caught: TypeError: condition.prev is undefined
parameters: [ "telescope_",
{ telescope_: <object of 20> },
{ key: null, type: null, defawlt: null, min: null, max: null, numBits: null, selection: null, error: null } ]
file: ../AddOns/station_options.oxp/Scripts/station_options.js
line: 1119, conditionNotMet( "MassLockViewDirn" )
line: 1216, formatOption( "MassLockViewDirn", [object Array] )
line: 1057, buildOptions( 22, "WW_next_pg" )
line: 954, displayOptions()
line: 900, initOptions( "telescope_" )
Code: Select all
Exception: TypeError: condition.prev is undefined
Active script: station_options 1.0
station_options.js, line 1119:
var goof = condition.prev.next;
Code: Select all
[script.javaScript.exception.unexpectedType]: ***** JavaScript exception (station_options 1.0): TypeError: condition.prev is undefined
[script.javaScript.exception.unexpectedType]: ../AddOns/station_options.oxp/Scripts/station_options.js, line 1119.
Of the 5 parameters to
_reportError
, only the first 3 are required:err
- the Error object the catch statement provides
func
- the function you're in (or a string with the function's name)
parms
- the parameter of that function; if more than one, put them in an array. Dispite the name, you can pass anything in the function's scope you want to be displayed.
The two optional ones deal with how much of the items in
parms
you want displayed.depth
- number of levels to recurse
goDeep
- boolean toggling object inheritance
The same example, now with
depth = 2
:
Code: Select all
function initOptions() caught: TypeError: condition.prev is undefined
parameters: [ "telescope_",
{ telescope_: { hostOxp: [Script "telescope" version 2.0], keyPrefix: "telescope_", optionsAllowedCallback: function _stnOptionsAllowed(), callPWSG: true, notifyCallback: function _reloadFromStn(), suppressSummary: false, hostVarPrefix: "$", lowestValue: "0", highestValue: null, maxPrecision: "7", maxVectorLen: "2", allow_reset: true, formatting: true, optionPages: <object of 4>, pageLabels: [ "config", "inflight", "UI_and_docs", "experimental" ], optionTabStops: <array of 4>, interface_title: "Telescope Options", interface_summary: "Edit all hardware and in-flight options; includes quick start & readme", interface_category: "Ship Systems", callback: function () } },
{ key: null, type: null, defawlt: null, min: null, max: null, numBits: null, selection: null, error: null } ]
file: ../AddOns/station_options.oxp/Scripts/station_options.js
line: 1119, conditionNotMet( "MassLockViewDirn" )
line: 1216, formatOption( "MassLockViewDirn", [object Array] )
line: 1057, buildOptions( 22, "WW_next_pg" )
line: 954, displayOptions()
line: 900, initOptions( "telescope_" )
depth = 3
:
Code: Select all
function initOptions() caught: TypeError: condition.prev is undefined
parameters: [ "telescope_",
{ telescope_: { hostOxp: [Script "telescope" version 2.0],
keyPrefix: "telescope_",
optionsAllowedCallback: function _stnOptionsAllowed(),
callPWSG: true,
notifyCallback: function _reloadFromStn(),
suppressSummary: false,
hostVarPrefix: "$",
lowestValue: "0",
highestValue: null,
maxPrecision: "7",
maxVectorLen: "2",
allow_reset: true,
formatting: true,
optionPages: { config: [ "Brief", "AutoScan", "AutoScanMaxRange", "FarStatus", "AutoLock", "GravLock", "IdentLock", "IdentDelay", "LightBallMinDist", "LightBallShipMinDist", "ShowMassLock", "MassLockViewDirn", "RedAlertDist", "SniperRingSize", "SniperRingColor", "ModelRingColor", "VTarget_HUD_shift" ], inflight: [ "Keys", "RemoveInFlight", "LightBalls", "ShipLightBalls", "LargeLightBalls", "MassLockBorders", "BrightMassLockBorders", "SniperMinRange", "SniperRange", "Steering", "MaxTargets", "ShowVisualTarget", "VisualTargetNormalSize", "VisualTargetCombatSize", "VisualTargetRing", "ShowVisualStation", "ShowVisualQuestionMark" ], UI_and_docs: [ "ConsoleMsgDurn", "GravScanMsgFreq", "IdentMessages", "DebugMessages", "ShowSummary", "FrameRate", "EffectData", "QuickStart", "Equipment", "Extender", "Support", "ReleaseNotes" ], experimental: [ "MFDFiltering", "MFDPrimaryStatic", "MFDPrimaryDynamic", "SeparateMFDs", "MFDAuxStatic", "MFDAuxDynamic", "Thargoids" ] },
pageLabels: [ "config", "inflight", "UI_and_docs", "experimental" ],
optionTabStops: [ [ 8.4, 14.6 ], [ 10.4, 14 ], [ 8, 10.5 ], [ 8.6, 12 ] ],
interface_title: "Telescope Options",
interface_summary: "Edit all hardware and in-flight options; includes quick start & readme",
interface_category: "Ship Systems",
callback: function () } },
{ key: null, type: null, defawlt: null, min: null, max: null, numBits: null, selection: null, error: null } ]
file: ../AddOns/station_options.oxp/Scripts/station_options.js
line: 1119, conditionNotMet( "MassLockViewDirn" )
line: 1216, formatOption( "MassLockViewDirn", [object Array] )
line: 1057, buildOptions( 22, "WW_next_pg" )
line: 954, displayOptions()
line: 900, initOptions( "telescope_" )
goDeep
; it's just more of the same. If the default output is too large, there's always depth = 0
:
Code: Select all
function initOptions() caught: TypeError: condition.prev is undefined
parameters: [ "telescope_", <object of 1>, { key: null, type: null, defawlt: null, min: null, max: null, numBits: null, selection: null, error: null } ]
file: ../AddOns/station_options.oxp/Scripts/station_options.js
line: 1119, conditionNotMet( "MassLockViewDirn" )
line: 1216, formatOption( "MassLockViewDirn", [object Array] )
line: 1057, buildOptions( 22, "WW_next_pg" )
line: 954, displayOptions()
line: 900, initOptions( "telescope_" )
depth
(pass depth as an array, eg. [ 2, 1 ]).There's a more complete explanation in the file itself. Just paste it into your script and you're good to go.
https://www.dropbox.com/s/cjldriko9aaq ... r.js?dl=0