Files
codeql/ql/src/experimental/InconsistentCode/GORMErrorNotChecked.qhelp
Sauyon Lee 1ffeb26a61 Add query for a GORM error not checked
co-authored-by: Sam Partington <sampart@github.com>
co-authored-by: Robin Neatherway <rneatherway@github.com>
2021-08-11 18:15:23 -07:00

35 lines
769 B
XML

<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>GORM errors are returned as a field of the return value instead of a separate return value.</p>
<p>It is therefore very easy to miss that an error may occur and omit error handling routines.</p>
</overview>
<recommendation>
<p>Ensure that GORM errors are checked.</p>
</recommendation>
<example>
<p>In the example below, the error from the database query is never checked:</p>
<sample src="GORMErrorNotChecked.go" />
<p>The corrected version checks and handles the error before returning.</p>
<sample src="GORMErrorNotCheckedGood.go" />
</example>
<references>
<li>
<a href="https://gorm.io/docs/error_handling.html">GORM Error Handling</a>.
</li>
</references>
</qhelp>