Skip to content

Commit 2f20d8e

Browse files
committed
Merge: alertOrLog_ for pre-visible renders
2 parents dfbe0bc + db05228 commit 2f20d8e

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

libs/FastSenseCompanion/InspectorPane.m

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,33 @@ function setState(obj, state, payload)
165165
obj.Payload_ = payload;
166166
obj.renderState_();
167167
catch err
168-
if ~isempty(obj.hFig_) && isvalid(obj.hFig_)
168+
obj.alertOrLog_(err);
169+
end
170+
end
171+
172+
function alertOrLog_(obj, err)
173+
%ALERTORLOG_ Best-effort error surface that won't crash on invisible figures.
174+
% Use this instead of raw uialert in catch blocks: uialert refuses
175+
% figures with Visible='off' (e.g. mid-construction during attach()).
176+
% We always print the error to stderr for diagnostics, then alert
177+
% only when the figure is up. Stack info goes to stderr too so we
178+
% never lose the original failure.
179+
try
180+
fprintf(2, '[InspectorPane] %s\n', err.message);
181+
if ~isempty(err.stack)
182+
for k = 1:min(3, numel(err.stack))
183+
fprintf(2, ' at %s (line %d)\n', ...
184+
err.stack(k).name, err.stack(k).line);
185+
end
186+
end
187+
catch
188+
end
189+
try
190+
if ~isempty(obj.hFig_) && isvalid(obj.hFig_) ...
191+
&& strcmp(obj.hFig_.Visible, 'on')
169192
uialert(obj.hFig_, err.message, 'FastSense Companion');
170-
else
171-
rethrow(err);
172193
end
194+
catch
173195
end
174196
end
175197

@@ -209,9 +231,7 @@ function renderState_(obj)
209231
'Unknown inspector state: ''%s''.', obj.State_);
210232
end
211233
catch err
212-
if ~isempty(obj.hFig_) && isvalid(obj.hFig_)
213-
uialert(obj.hFig_, err.message, 'FastSense Companion');
214-
end
234+
obj.alertOrLog_(err);
215235
end
216236
end
217237

0 commit comments

Comments
 (0)