-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A new exception to suppress exception logs #30771
Conversation
Codecov Report
@@ Coverage Diff @@
## master #30771 +/- ##
============================================
+ Coverage 62.18% 62.32% +0.14%
- Complexity 18214 18217 +3
============================================
Files 1143 1143
Lines 68210 68216 +6
Branches 1232 1232
============================================
+ Hits 42416 42516 +100
+ Misses 25433 25339 -94
Partials 361 361
Continue to review full report at Codecov.
|
|
||
/** | ||
* Exception for invalid content | ||
* @since 6.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10.0.8 or 10.1.0 ? :unsure:
|
||
/** | ||
* Public interface of ownCloud for apps to use. | ||
* Files/InvalidContentException class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c&p ;)
* Exception for invalid content | ||
* @since 6.0.0 | ||
*/ | ||
class ExcludeForbiddenException extends \Exception {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What HTTP status will get a desktop client in this case, something like 50x? Imho this exception should extend ForbiddenException
... and files_ antivirus should throw it with $retry=true
https://github.com/owncloud/core/blob/master/lib/public/Files/ForbiddenException.php#L43
@@ -601,6 +602,10 @@ private function needsPartFile($storage) { | |||
* @throws \Sabre\DAV\Exception | |||
*/ | |||
private function convertToSabreException(\Exception $e) { | |||
if ($e instanceof ExcludeForbiddenException) { | |||
// the file content is not permitted | |||
throw new UnsupportedMediaType($e->getMessage(), 0, $e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not that critical to have exactly UnsupportedMediaType
exception here. Actually back then I was choosing between 415 Unsupported Media Type and 418 I'm a teapot. And some people consider 415 status for infected files to be a bug nowadays, see owncloud/files_antivirus#177 ;)
If 403 is properly escalates exception message to the frontend we can just rethrow ExcludeForbiddenException
(subclassed from ForbiddenException
as requested above)
ff729e0
to
bdd10d1
Compare
namespace OCP\Files; | ||
|
||
/** | ||
* Exception for invalid content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sharidas Class description needs to be updated too. 'ForbiddenException with suppressed logging' or so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VicDeo Done.
bdd10d1
to
2bd142b
Compare
Works as expected. There are no extra entries in log, Antivirus message is properly escalated to UI. |
@PVince81 please consider backport to stable10 or files_antivirus will need a separate branch to support stable10 |
@@ -175,7 +176,11 @@ public function createFile($name, $data = null) { | |||
} catch (InvalidPathException $ex) { | |||
throw new InvalidPath($ex->getMessage()); | |||
} catch (ForbiddenException $ex) { | |||
throw new Forbidden($ex->getMessage(), $ex->getRetry()); | |||
if ($ex->getPrevious() instanceof ExcludeForbiddenException) { | |||
throw new ExcludeForbiddenException($ex->getMessage(), $ex->getRetry(), $ex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feels rather hacky. we can't create a subclass for every possible exception that we don't want to be logged.
or rename this exception with a name like "FileContentNotAllowedException" which is not semantically about "prevent logging" but about the actual error which is about disallowed file contents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, renaming ExcludeForbidenException
to FileContentNotAllowedException
.
@VicDeo I will update owncloud/files_antivirus#219 accordingly.
2bd142b
to
f46b787
Compare
|
||
/** | ||
* FileContentNotAllowed to suppress logging. | ||
* @since 10.1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make that 10.0.8 if you think we can backport in time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There are scenarios where an app would have done the job and the logger would have logged. But the main task would throw an exception. Since its logged gracefully we need not throw exception in the log. This change would help for the same. Signed-off-by: Sujith H <sharidasan@owncloud.com>
f46b787
to
f38b692
Compare
Updated the PR as requested. |
Backport PR: #30991 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
There are scenarios where an app would have
done the job and the logger would have logged.
But the main task would throw an exception.
Since its logged gracefully we need not throw
exception in the log. This change would help
for the same.
Signed-off-by: Sujith H sharidasan@owncloud.com
Description
There can be situations where we need not throw the exceptions to the logger. For example when an antivirus app had detected the file cannot be uploaded and logged gracefully, it would be nice to exclude the exception logged.
Related Issue
#30751
Motivation and Context
There can be situations where we need not throw the exceptions to the logger. For example when an antivirus app had detected the file cannot be uploaded and logged gracefully, it would be nice to exclude the exception logged.
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: