fn_trace_gettable() reports an error The following code returns some rows with [Error] = 2


SELECT
 v1.[name] as EventName, tr.TextData, tr.HostName, tr.ApplicationName, tr.LoginName, tr.SPID, tr.Duration, 
 tr.StartTime, tr.EndTime, tr.Reads, tr.Writes, tr.CPU, tr.ServerName, tr.Error, tr.ObjectName, tr.RowCounts
FROM 
 sys.trace_events as v1
 INNER JOIN fn_trace_gettable(@v_path, DEFAULT) as tr ON tr.EventClass = v1.trace_event_id 
WHERE 
 tr.TextData IS NOT NULL AND
 (tr.EndTime &gt; @v_maxEndTime OR @v_maxEndTime IS NULL)
 OPTION(RECOMPILE);



Where can I see the list of error codes for fn_trace_gettable to understand what this one means?
The most common error codes when tracing regular query execution will be 0, 1 or 2.

0 = OK, 1 = Error, 2 = Abort


Source

In your case, error code 2 = abort, meaning that a query was cancelled due to such things as a timeout or a user action.

You can test this by starting a trace, running a query and stopping it before execution end:



The official definition shows that other error messages might be shown dependent on which events you select:



The same is true for the docs on traces.



These errors and their definition can be found in:

SELECT * 
FROM sys.sysmessages;




Testing this could be done by selecting error events:



Running a divide by zero query to produce an error:



Finding the exception error number:



And then querying sys.sysmessages:

SELECT * 
FROM sys.sysmessages
where error = 8134;


Result: