python: Report detailed error message when opening fsread1 channel fails

Teach check_open() about validating the `message` part of `close`, when
given.
This commit is contained in:
Martin Pitt 2023-02-02 16:04:30 +01:00 committed by Allison Karlitskaya
parent 60291fd727
commit 3151a8c9bf
2 changed files with 8 additions and 2 deletions

View File

@ -109,8 +109,8 @@ class FsReadChannel(GeneratorChannel):
return {'tag': '-'}
except PermissionError:
raise ChannelError('access-denied')
except OSError:
raise ChannelError('internal-error')
except OSError as error:
raise ChannelError('internal-error', message=str(error)) from error
class FsReplaceChannel(Channel):

View File

@ -510,3 +510,9 @@ class TestBridge(unittest.IsolatedAsyncioTestCase):
assert not all(d for d in data[0][0])
# memory.used should be an integer
assert isinstance(data[0][1], int)
async def test_fsread1_errors(self):
await self.start()
await self.transport.check_open('fsread1', path='/etc/shadow', problem='access-denied')
await self.transport.check_open('fsread1', path='/', problem='internal-error',
reply_keys={'message': "[Errno 21] Is a directory: '/'"})