Skip to content

Commit 7716368

Browse files
authored
Merge pull request #2585 from AllenInstitute/bugfix/2585-better-error-reporting
Improve error reporting and localisation options for lingering RTEs
2 parents 57a6297 + 3f24022 commit 7716368

File tree

8 files changed

+172
-58
lines changed

8 files changed

+172
-58
lines changed

Packages/MIES/MIES_AnalysisFunctionManagement.ipf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/// @return Valid analysis function return types, zero otherwise, see also @ref AnalysisFunctionReturnTypes
1515
Function AFM_CallAnalysisFunctions(string device, variable eventType)
1616

17-
variable i, valid_f1, valid_f2, valid_f3, ret, DAC, sweepsInSet, hwIsSutter
17+
variable i, valid_f1, valid_f2, valid_f3, ret, DAC, sweepsInSet, hwIsSutter, err
1818
variable realDataLengthAD, realDataLengthDA, sweepNo, fifoPositionAD, fifoPositionDA, sampleIntDA, sampleIntAD
1919
string func, msg
2020
STRUCT AnalysisFunction_V3 s
@@ -170,8 +170,12 @@ Function AFM_CallAnalysisFunctions(string device, variable eventType)
170170
endif
171171
catch
172172
msg = GetRTErrMessage()
173-
ClearRTError()
174-
printf "The analysis function %s aborted with error \"%s\", this is dangerous and must *not* happen!\r", func, msg
173+
err = ClearRTError()
174+
if(err)
175+
printf "The analysis function %s aborted due to a runtime error (%d) \"%s\".\r", func, err, msg
176+
else
177+
printf "The analysis function %s aborted with V_AbortCode (%d).\r", func, V_AbortCode
178+
endif
175179

176180
NVAR errorCounter = $GetAnalysisFuncErrorCounter(device)
177181
errorCounter += 1

Packages/MIES/MIES_ExperimentDocumentation.ipf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,10 @@ static Function ED_createTextNotes(WAVE/T incomingTextualValues, WAVE/T incoming
192192

193193
numCols = DimSize(incomingTextualValues, COLS)
194194
lastValidIncomingLayer = (DimSize(incomingTextualValues, LAYERS) == 0) ? 0 : (DimSize(incomingTextualValues, LAYERS) - 1)
195+
196+
AssertOnAndClearRTError()
195197
for(i = 0; i < numCols; i += 1)
196-
values[rowIndex][indizes[i]][0, lastValidIncomingLayer] = NormalizeToEOL(incomingTextualValues[0][i][r], "\n")
198+
values[rowIndex][indizes[i]][0, lastValidIncomingLayer] = NormalizeToEOL(incomingTextualValues[0][i][r], "\n"); AbortOnRTE
197199
endfor
198200

199201
SetNumberInWaveNote(values, NOTE_INDEX, rowIndex + 1)
@@ -295,8 +297,10 @@ static Function ED_createWaveNotes(WAVE incomingNumericalValues, WAVE/T incoming
295297

296298
numCols = DimSize(incomingNumericalValues, COLS)
297299
lastValidIncomingLayer = (DimSize(incomingNumericalValues, LAYERS) == 0) ? 0 : (DimSize(incomingNumericalValues, LAYERS) - 1)
300+
301+
AssertOnAndClearRTError()
298302
for(i = 0; i < numCols; i += 1)
299-
values[rowIndex][indizes[i]][0, lastValidIncomingLayer] = incomingNumericalValues[0][i][r]
303+
values[rowIndex][indizes[i]][0, lastValidIncomingLayer] = incomingNumericalValues[0][i][r]; AbortOnRTE
300304
endfor
301305

302306
SetNumberInWaveNote(values, NOTE_INDEX, rowIndex + 1)

Packages/MIES/MIES_MiesUtilities_Logbook.ipf

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,8 @@ threadsafe Function/WAVE GetLastSetting(WAVE values, variable sweepNo, string se
625625
first = rowCache[sweepNo][%first][entrySourceTypeIndex]
626626
last = rowCache[sweepNo][%last][entrySourceTypeIndex]
627627

628-
WAVE/Z settings = GetLastSettingNoCache(values, sweepNo, setting, entrySourceType, \
629-
first = first, last = last, rowIndex = rowIndex)
628+
WAVE/Z settings = GetLastSettingNoCache(values, sweepNo, setting, entrySourceType, \
629+
first = first, last = last, rowIndex = rowIndex, settingCol = settingCol)
630630

631631
if(WaveExists(settings))
632632
ASSERT_TS(first >= 0 && last >= 0 && rowIndex >= 0, "invalid return combination from GetLastSettingNoCache")
@@ -749,8 +749,10 @@ threadsafe Function/WAVE GetLastSettingNoCache(WAVE values, variable sweepNo, st
749749
endif
750750
endif
751751

752-
statusText[] = textualValues[i][settingCol][p]
753-
lengths[] = strlen(statusTexT[p])
752+
AssertOnAndClearRTError()
753+
statusText[] = textualValues[i][settingCol][p]; AbortOnRTE
754+
755+
lengths[] = strlen(statusTexT[p])
754756

755757
// return if we have at least one non-empty entry
756758
if(Sum(lengths) > 0)
@@ -848,7 +850,8 @@ threadsafe Function/WAVE GetLastSettingNoCache(WAVE values, variable sweepNo, st
848850
endif
849851
endif
850852

851-
status[] = numericalValues[i][settingCol][p]
853+
AssertOnAndClearRTError()
854+
status[] = numericalValues[i][settingCol][p]; AbortOnRTE
852855

853856
if(HasOneValidEntry(status))
854857
if(!ParamIsDefault(rowIndex))
@@ -1984,3 +1987,40 @@ Function/S StringifyLogbookMode(variable mode)
19841987
break
19851988
endswitch
19861989
End
1990+
1991+
/// @brief Invalidates the row and index caches for all labnotebook and results wave
1992+
Function InvalidateLBIndexAndRowCaches()
1993+
1994+
string device
1995+
1996+
DFREF dfr = GetCacheFolder()
1997+
1998+
if(IsDataFolderEmpty(dfr))
1999+
return NaN
2000+
endif
2001+
2002+
WAVE/T devices = ListToTextWave(GetAllDevices(), ";")
2003+
2004+
// labnotebook (numerical and textual) of all devices
2005+
for(device : devices)
2006+
Make/FREE/WAVE valuesWave = {GetLBNumericalValues(device), GetLBTextualValues(device)}
2007+
2008+
InvalidateLBIndexAndRowCaches_Impl(valuesWave)
2009+
endfor
2010+
2011+
Make/FREE/WAVE valuesWave = {GetNumericalResultsValues(), GetTextualResultsValues()}
2012+
InvalidateLBIndexAndRowCaches_Impl(valuesWave)
2013+
End
2014+
2015+
static Function InvalidateLBIndexAndRowCaches_Impl(WAVE valuesWave)
2016+
2017+
string key
2018+
2019+
for(WAVE values : valuesWave)
2020+
Make/FREE/T keys = {CA_CreateLBIndexCacheKey(values), CA_CreateLBRowCacheKey(values)}
2021+
2022+
for(key : keys)
2023+
CA_DeleteCacheEntry(key)
2024+
endfor
2025+
endfor
2026+
End

Packages/MIES/MIES_MiesUtilities_System.ipf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ Function BackupCacheWaves()
213213
variable i, numEntries
214214
string names = ""
215215

216+
InvalidateLBIndexAndRowCaches()
217+
216218
DFREF dfr = GetCacheFolder()
217219

218220
WAVE/WAVE cacheWaves = ListToWaveRefWave(GetListOfObjects(dfr, ".*", fullPath = 1))

Packages/MIES/MIES_Utilities_ProgramFlow.ipf

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ Function ASSERT(variable var, string errorMsg, [variable extendedOutput])
148148
try
149149
AbortOnValue var == 0, 1
150150
catch
151+
#ifndef AUTOMATED_TESTING
152+
AssertOnAndClearRTError()
153+
#endif // !AUTOMATED_TESTING
154+
151155
if(ParamIsDefault(extendedOutput))
152156
extendedOutput = 1
153157
else
@@ -201,6 +205,7 @@ Function ASSERT(variable var, string errorMsg, [variable extendedOutput])
201205
Make/FREE/T tpStates = {NONE}
202206
Make/FREE/T daqStates = {NONE}
203207
Make/FREE/T acqStates = {NONE}
208+
Make/FREE/T fifoPos = {NONE}
204209

205210
if(!SVAR_Exists(lockedDevices) || IsEmpty(lockedDevices))
206211
lockedDevicesStr = NONE
@@ -209,7 +214,7 @@ Function ASSERT(variable var, string errorMsg, [variable extendedOutput])
209214

210215
numLockedDevices = ItemsInList(lockedDevicesStr)
211216

212-
Redimension/N=(numLockedDevices) sweeps, daqStates, tpStates, acqStates
217+
Redimension/N=(numLockedDevices) sweeps, daqStates, tpStates, acqStates, fifoPos
213218

214219
for(i = 0; i < numLockedDevices; i += 1)
215220
device = StringFromList(i, lockedDevicesStr)
@@ -220,6 +225,7 @@ Function ASSERT(variable var, string errorMsg, [variable extendedOutput])
220225
tpStates[i] = TestPulseRunModeToString(testpulseMode)
221226
daqStates[i] = DAQRunModeToString(runMode)
222227
acqStates[i] = AS_StateToString(ROVar(GetAcquisitionState(device)))
228+
fifoPos[i] = num2istr(ROVar(GetFifoPosition(device)))
223229
endfor
224230
endif
225231

@@ -232,12 +238,13 @@ Function ASSERT(variable var, string errorMsg, [variable extendedOutput])
232238
print stacktrace
233239

234240
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
235-
printf "Time: %s\r", GetIso8601TimeStamp(localTimeZone = 1)
241+
printf "Time: %s\r", GetIso8601TimeStamp(localTimeZone = 1, numFracSecondsDigits = 3)
236242
printf "Locked device: [%s]\r", RemoveEnding(lockedDevicesStr, ";")
237243
printf "Current sweep: [%s]\r", TextWaveToList(sweeps, ";", trailSep = 0)
238244
printf "DAQ: [%s]\r", TextWaveToList(daqStates, ";", trailSep = 0)
239245
printf "Testpulse: [%s]\r", TextWaveToList(tpStates, ";", trailSep = 0)
240246
printf "Acquisition state: [%s]\r", TextWaveToList(acqStates, ";", trailSep = 0)
247+
printf "Fifo position: [%s]\r", TextWaveToList(fifoPos, ";", trailSep = 0)
241248
printf "Experiment: %s (%s)\r", GetExperimentName(), GetExperimentFileType()
242249
printf "Igor Pro version: %s (%s)\r", GetIgorProVersion(), GetIgorProBuildVersion()
243250
print "MIES version:"
@@ -284,6 +291,10 @@ threadsafe Function ASSERT_TS(variable var, string errorMsg, [variable extendedO
284291
try
285292
AbortOnValue var == 0, 1
286293
catch
294+
#ifndef AUTOMATED_TESTING
295+
AssertOnAndClearRTError()
296+
#endif // !AUTOMATED_TESTING
297+
287298
if(ParamIsDefault(extendedOutput))
288299
extendedOutput = 1
289300
else
@@ -319,7 +330,7 @@ threadsafe Function ASSERT_TS(variable var, string errorMsg, [variable extendedO
319330
print stacktrace
320331

321332
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
322-
printf "Time: %s\r", GetIso8601TimeStamp(localTimeZone = 1)
333+
printf "Time: %s\r", GetIso8601TimeStamp(localTimeZone = 1, numFracSecondsDigits = 3)
323334
printf "Experiment: %s (%s)\r", GetExperimentName(), GetExperimentFileType()
324335
printf "Igor Pro version: %s (%s)\r", GetIgorProVersion(), GetIgorProBuildVersion()
325336
print "################################"

Packages/MIES/MIES_WaveDataFolderGetters.ipf

Lines changed: 62 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,7 @@ End
22182218
/// - One for each entrySourceType, mapped via EntrySourceTypeMapper()
22192219
threadsafe Function/WAVE GetLBRowCache(WAVE values)
22202220

2221-
variable actual, sweepNo, first, last
2221+
variable actual, sweepNo, first, last, expected
22222222
string key
22232223

22242224
variable versionOfNewWave = 6
@@ -2229,32 +2229,41 @@ threadsafe Function/WAVE GetLBRowCache(WAVE values)
22292229
WAVE/Z/D wv = CA_TryFetchingEntryFromCache(key, options = CA_OPTS_NO_DUPLICATE)
22302230

22312231
if(ExistsWithCorrectLayoutVersion(wv, versionOfNewWave))
2232-
if(actual == GetNumberFromWaveNote(wv, LABNOTEBOOK_MOD_COUNT))
2232+
expected = GetNumberFromWaveNote(wv, LABNOTEBOOK_MOD_COUNT)
2233+
2234+
// wave modification count tracking is only reliable while running
2235+
// inside a single experiment, not across experiments
2236+
if(actual == expected)
22332237
return wv
22342238
elseif(!MU_RunningInMainThread() && GetLockState(values) == 1)
22352239
return wv
22362240
else
2237-
// new entries were added so we need to propagate all entries to LABNOTEBOOK_GET_RANGE
2238-
// for sweep numbers >= than the currently acquired sweep
2239-
// this is required as the `last` element of the range can be changed if you add labnotebook
2240-
// entries and then query them and then add again.
2241-
2242-
if(IsNumericWave(values))
2243-
WAVE/Z sweeps = GetLastSweepWithSetting(values, "SweepNum", sweepNo)
2244-
elseif(IsTextWave(values))
2245-
WAVE/Z sweeps = GetLastSweepWithSettingText(values, "SweepNum", sweepNo)
2246-
endif
2247-
2248-
if(IsFinite(sweepNo))
2249-
EnsureLargeEnoughWave(wv, indexShouldExist = sweepNo, dimension = ROWS, initialValue = LABNOTEBOOK_GET_RANGE)
2250-
first = limit(sweepNo - 1, 0, Inf)
2251-
last = sweepNo
2252-
Multithread wv[first, last][][] = LABNOTEBOOK_GET_RANGE
2253-
2254-
// now we are up to date
2255-
SetNumberInWaveNote(wv, LABNOTEBOOK_MOD_COUNT, actual)
2256-
2257-
return wv
2241+
if(actual > expected)
2242+
// new entries were added so we need to propagate all entries to LABNOTEBOOK_GET_RANGE
2243+
// for sweep numbers >= than the currently acquired sweep
2244+
// this is required as the `last` element of the range can be changed if you add labnotebook
2245+
// entries and then query them and then add again.
2246+
2247+
if(IsNumericWave(values))
2248+
WAVE/Z sweeps = GetLastSweepWithSetting(values, "SweepNum", sweepNo)
2249+
elseif(IsTextWave(values))
2250+
WAVE/Z sweeps = GetLastSweepWithSettingText(values, "SweepNum", sweepNo)
2251+
endif
2252+
2253+
if(IsFinite(sweepNo))
2254+
EnsureLargeEnoughWave(wv, indexShouldExist = sweepNo, dimension = ROWS, initialValue = LABNOTEBOOK_GET_RANGE)
2255+
first = limit(sweepNo - 1, 0, Inf)
2256+
last = sweepNo
2257+
Multithread wv[first, last][][] = LABNOTEBOOK_GET_RANGE
2258+
2259+
// now we are up to date
2260+
SetNumberInWaveNote(wv, LABNOTEBOOK_MOD_COUNT, actual)
2261+
2262+
return wv
2263+
endif
2264+
else
2265+
// cache across experiments, so the stored wave modification is
2266+
// larger than the last labnotebook we cached, go for a full reset
22582267
endif
22592268
endif
22602269
else
@@ -2293,7 +2302,7 @@ End
22932302
/// could not be found, and #LABNOTEBOOK_UNCACHED_VALUE if the cache is empty.
22942303
threadsafe Function/WAVE GetLBIndexCache(WAVE values)
22952304

2296-
variable actual, sweepNo, first, last
2305+
variable actual, sweepNo, first, last, expected
22972306
string key
22982307

22992308
variable versionOfNewWave = 5
@@ -2304,30 +2313,39 @@ threadsafe Function/WAVE GetLBIndexCache(WAVE values)
23042313
WAVE/Z/D wv = CA_TryFetchingEntryFromCache(key, options = CA_OPTS_NO_DUPLICATE)
23052314

23062315
if(ExistsWithCorrectLayoutVersion(wv, versionOfNewWave))
2307-
if(actual == GetNumberFromWaveNote(wv, LABNOTEBOOK_MOD_COUNT))
2316+
expected = GetNumberFromWaveNote(wv, LABNOTEBOOK_MOD_COUNT)
2317+
2318+
// wave modification count tracking is only reliable while running
2319+
// inside a single experiment, not across experiments
2320+
if(actual == expected)
23082321
return wv
23092322
elseif(!MU_RunningInMainThread() && GetLockState(values) == 1)
23102323
return wv
23112324
else
2312-
// new entries were added so we need to propagate all entries to uncached values
2313-
// for sweep numbers >= than the currently acquired sweep
2314-
2315-
if(IsNumericWave(values))
2316-
WAVE/Z sweeps = GetLastSweepWithSetting(values, "SweepNum", sweepNo)
2317-
elseif(IsTextWave(values))
2318-
WAVE/Z sweeps = GetLastSweepWithSettingText(values, "SweepNum", sweepNo)
2319-
endif
2320-
2321-
if(IsFinite(sweepNo))
2322-
EnsureLargeEnoughWave(wv, indexShouldExist = sweepNo, dimension = ROWS, initialValue = LABNOTEBOOK_UNCACHED_VALUE)
2323-
first = limit(sweepNo - 1, 0, Inf)
2324-
last = sweepNo
2325-
Multithread wv[first, last][][] = LABNOTEBOOK_UNCACHED_VALUE
2326-
2327-
// now we are up to date
2328-
SetNumberInWaveNote(wv, LABNOTEBOOK_MOD_COUNT, actual)
2329-
2330-
return wv
2325+
if(actual > expected)
2326+
// new entries were added so we need to propagate all entries to uncached values
2327+
// for sweep numbers >= than the currently acquired sweep
2328+
2329+
if(IsNumericWave(values))
2330+
WAVE/Z sweeps = GetLastSweepWithSetting(values, "SweepNum", sweepNo)
2331+
elseif(IsTextWave(values))
2332+
WAVE/Z sweeps = GetLastSweepWithSettingText(values, "SweepNum", sweepNo)
2333+
endif
2334+
2335+
if(IsFinite(sweepNo))
2336+
EnsureLargeEnoughWave(wv, indexShouldExist = sweepNo, dimension = ROWS, initialValue = LABNOTEBOOK_UNCACHED_VALUE)
2337+
first = limit(sweepNo - 1, 0, Inf)
2338+
last = sweepNo
2339+
Multithread wv[first, last][][] = LABNOTEBOOK_UNCACHED_VALUE
2340+
2341+
// now we are up to date
2342+
SetNumberInWaveNote(wv, LABNOTEBOOK_MOD_COUNT, actual)
2343+
2344+
return wv
2345+
endif
2346+
else
2347+
// cache across experiments, so the stored wave modification is
2348+
// larger than the last labnotebook we cached, go for a full reset
23312349
endif
23322350
endif
23332351
else

Packages/tests/Basic/UTF_Utils_System.ipf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static Function TestCacheBackupAndRestore()
131131
DFREF dfr = GetCacheFolder()
132132

133133
name = GetListOfObjects(dfr, ".*")
134-
CHECK_EQUAL_STR(name, "data;")
134+
CHECK_EQUAL_STR(name, "data;keys;")
135135

136136
WAVE/Z/SDFR=dfr new = $StringFromList(0, name)
137137
CHECK(!WaveRefsEqual(new, old))

Packages/tests/HardwareAnalysisFunctions/UTF_PatchSeqDAScale_Sub.ipf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,3 +2349,38 @@ static Function PS_DS_Sub11_REENTRY([string str])
23492349
CommonAnalysisFunctionChecks(str, sweepNo, setPassed)
23502350
CheckPSQChunkTimes(str, {20, 520, 2020, 2520})
23512351
End
2352+
2353+
static Function PS_DS_Sub12_preAcq(string device)
2354+
2355+
Make/FREE asyncChannels = {2, 3}
2356+
AFH_AddAnalysisParameter("PSQ_DaScale_Sub_DA_0", "AsyncQCChannels", wv = asyncChannels)
2357+
2358+
SetAsyncChannelProperties(device, asyncChannels, -1e6, +1e6)
2359+
End
2360+
2361+
// UTF_TD_GENERATOR DataGenerators#DeviceNameGeneratorMD1
2362+
static Function PS_DS_Sub12([string str])
2363+
2364+
PS_DS_Sub2(str = str)
2365+
End
2366+
2367+
static Function PS_DS_Sub12_REENTRY([string str])
2368+
2369+
PS_DS_Sub2_REENTRY(str = str)
2370+
2371+
BackupCacheWaves()
2372+
End
2373+
2374+
// UTF_TD_GENERATOR DataGenerators#DeviceNameGeneratorMD1
2375+
static Function PS_DS_Sub13([string str])
2376+
2377+
CA_FLushCache()
2378+
RestoreCacheWaves()
2379+
2380+
PS_DS_Sub2(str = str)
2381+
End
2382+
2383+
static Function PS_DS_Sub13_REENTRY([string str])
2384+
2385+
PS_DS_Sub2_REENTRY(str = str)
2386+
End

0 commit comments

Comments
 (0)