Skip to content
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

Merged
merged 1 commit into from
Apr 3, 2018
Merged

Conversation

sharidas
Copy link
Contributor

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?

  • Uploaded the eicar test file and the exception is not logged.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov
Copy link

codecov bot commented Mar 13, 2018

Codecov Report

Merging #30771 into master will increase coverage by 0.14%.
The diff coverage is 71.42%.

Impacted file tree graph

@@             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
Flag Coverage Δ Complexity Δ
#javascript 52.04% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 63.49% <71.42%> (+0.15%) 18217 <0> (+3) ⬆️
Impacted Files Coverage Δ Complexity Δ
.../dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php 96.87% <100%> (+0.2%) 9 <0> (+1) ⬆️
apps/dav/lib/Connector/Sabre/File.php 83.57% <50%> (-0.25%) 108 <0> (+1)
apps/dav/lib/Connector/Sabre/Directory.php 70.62% <66.66%> (+0.37%) 74 <0> (+1) ⬆️
lib/private/DB/MDB2SchemaManager.php 91.22% <0%> (+5.26%) 17% <0%> (ø) ⬇️
...eryBuilder/ExpressionBuilder/ExpressionBuilder.php 95.89% <0%> (+5.47%) 20% <0%> (ø) ⬇️
lib/private/DB/ConnectionFactory.php 82.89% <0%> (+7.89%) 21% <0%> (ø) ⬇️
lib/private/DB/AdapterSqlite.php 83.33% <0%> (+83.33%) 7% <0%> (ø) ⬇️
lib/private/Repair/SqliteAutoincrement.php 85.18% <0%> (+85.18%) 9% <0%> (ø) ⬇️
lib/private/DB/OCSqlitePlatform.php 100% <0%> (+100%) 5% <0%> (ø) ⬇️
lib/private/DB/SQLiteSessionInit.php 100% <0%> (+100%) 4% <0%> (ø) ⬇️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c30c94d...f38b692. Read the comment docs.

@sharidas sharidas changed the title [WIP] A new exception to suppress exception logs A new exception to suppress exception logs Mar 16, 2018

/**
* Exception for invalid content
* @since 6.0.0
Copy link
Member

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
Copy link
Member

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 {}
Copy link
Member

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);
Copy link
Member

@VicDeo VicDeo Mar 22, 2018

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)

@sharidas sharidas force-pushed the suppress-exception-log branch 3 times, most recently from ff729e0 to bdd10d1 Compare March 23, 2018 10:31
namespace OCP\Files;

/**
* Exception for invalid content
Copy link
Member

@VicDeo VicDeo Mar 26, 2018

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VicDeo Done.

@VicDeo
Copy link
Member

VicDeo commented Mar 27, 2018

Works as expected. There are no extra entries in log, Antivirus message is properly escalated to UI.

@VicDeo
Copy link
Member

VicDeo commented Mar 27, 2018

@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);
Copy link
Contributor

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

Copy link
Contributor Author

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.


/**
* FileContentNotAllowed to suppress logging.
* @since 10.1.0
Copy link
Contributor

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

Copy link
Contributor

@PVince81 PVince81 left a 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>
@sharidas
Copy link
Contributor Author

sharidas commented Apr 3, 2018

Updated the PR as requested.

@sharidas
Copy link
Contributor Author

sharidas commented Apr 3, 2018

Backport PR: #30991

@sharidas sharidas merged commit c59a9d1 into master Apr 3, 2018
@sharidas sharidas deleted the suppress-exception-log branch April 3, 2018 12:07
@lock
Copy link

lock bot commented Jul 31, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants