Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions command_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,12 @@ def savestate_filename(input_dict, environment_dict):
environment_dict['cmdargs'], environment_dict['defaulttarget'],
environment_dict['defaultkeyname'], environment_dict['autosave'],
environment_dict['currentkeyname'])
except TypeError:
raise seash_exceptions.UserError("Please load at least a pubkey, and work as that identity.")

except UnboundLocalError:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This (and the TypeError above) feel odd to check against, even if that is what seash_helper currently raises.

Can we make seash_helper raise more appropriate exceptions? How do its other commands deal with situations like these?

raise seash_exceptions.UserError("Don't use savestate to a write-protected file.")

except Exception, error:
raise seash_exceptions.UserError("Error saving state: '" + str(error) + "'.")

Expand Down
38 changes: 38 additions & 0 deletions tests/ut_seash_savestate_nicermessage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
This unit test is to test error messages at these situations. One is using
savestate before having loaded at least a pubkey, and work as that identity.
Another is using savestate to a write-protected file.
"""

import seash
import sys
import os
import seash_exceptions

#pragma out Please load at least a pubkey, and work as that identity.
#pragma out Don't use savestate to a write-protected file.

open('write_protected_file', 'w+').close()
os.system('chmod a-w write_protected_file')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This won't work cross-platform (think Windows).


command_list = [
'savestate NO_KEYS_LOADED',
]

try:
seash.command_loop(command_list)
except seash_exceptions.UserError, e:
print str(e)

command_list = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ideally, we would have the second test as a separate unit test file. Otherwise, you can't really say which of the tests failed.

'loadkeys guest0',
'as guest0',
'savestate write_protected_file',
]

try:
seash.command_loop(command_list)
except seash_exceptions.UserError, e:
print str(e)

os.remove('write_protected_file')