Skip to content

Commit e81c793

Browse files
committed
refine error checking in AutoTrace
1 parent cc03693 commit e81c793

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

auto-instrumentation/+opentelemetry/+autoinstrument/AutoTrace.m

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,17 @@ function processFileInput(f)
159159
f = string(f); % force into a string
160160
if startsWith(f, '@') % check for anonymous function
161161
error("opentelemetry:autoinstrument:AutoTrace:AnonymousFunction", ...
162-
f + " is an anonymous function and is not supported.");
162+
replace(f, "\", "\\") + " is an anonymous function and is not supported.");
163163
end
164-
if exist(f, "file") ~= 2
165-
error("opentelemetry:autoinstrument:AutoTrace:InvalidMFile", ...
166-
f + " is not found or is not a valid MATLAB file with a .m extension.")
164+
[~,~,fext] = fileparts(f); % check file extension
165+
filetype = exist(f, "file"); % check file type
166+
if ~(filetype == 2 && ismember(fext, ["" ".m" ".mlx"]))
167+
if exist(f, "builtin")
168+
error("opentelemetry:autoinstrument:AutoTrace:BuiltinFunction", ...
169+
replace(f, "\", "\\") + " is a builtin function and is not supported.");
170+
else
171+
error("opentelemetry:autoinstrument:AutoTrace:InvalidMFile", ...
172+
replace(f, "\", "\\") + " is not found or is not a valid MATLAB file with a .m or .mlx extension.");
173+
end
167174
end
168175
end

test/tautotrace.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,10 @@ function testInvalidInputFunction(testCase)
242242
verifyError(testCase, @()opentelemetry.autoinstrument.AutoTrace(@()example1), "opentelemetry:autoinstrument:AutoTrace:AnonymousFunction");
243243

244244
% builtin function
245-
verifyError(testCase, @()opentelemetry.autoinstrument.AutoTrace(@uplus), "opentelemetry:autoinstrument:AutoTrace:InvalidMFile");
245+
verifyError(testCase, @()opentelemetry.autoinstrument.AutoTrace(@uplus), "opentelemetry:autoinstrument:AutoTrace:BuiltinFunction");
246+
247+
% nonexistent function
248+
verifyError(testCase, @()opentelemetry.autoinstrument.AutoTrace(@bogus), "opentelemetry:autoinstrument:AutoTrace:InvalidMFile");
246249
end
247250
end
248251
end

0 commit comments

Comments
 (0)