mock-aws-s3 icon indicating copy to clipboard operation
mock-aws-s3 copied to clipboard

Support NoSuchKey errors for missing objects instead of file IO errors

Open mxro opened this issue 4 months ago • 0 comments

As reported in https://github.com/goldstack/goldstack/issues/460, this library currently does not throw NoSuchKey errors when an object does not exist.

Workaround: I've written some simple wrappers in: https://github.com/goldstack/goldstack/pull/462/files#diff-3aeb69b76fe6d60e2e86dfce2a619f2ec35df67c272678b7aea057b253aff9a5

      if (['headObject', 'getObjectTagging', 'putObjectTagging', 'copyObject'].includes(method)) {
        try {
          const result = await operation.promise();
          if (method === 'headObject' && result === undefined) {
            throw new NoSuchKey({
              message: 'The specified key does not exist.',
              $metadata: {},
            });
          }
          return result;
        } catch (e) {
          const awsError = e as AWSError;
          if (awsError.code === 'NoSuchKey' || awsError.code === 'ENOENT') {
            throw new NoSuchKey({
              message: e.message,
              $metadata: {},
            });
          }
          throw e;
        }
      }

mxro avatar Nov 27 '25 04:11 mxro