Use ShowExceptionDialog when we want to show ErrorReportDialog
This commit is contained in:
parent
bbb9ca14a2
commit
690772ccb0
|
@ -23,8 +23,10 @@ AudacityException::~AudacityException()
|
|||
|
||||
wxAtomicInt sOutstandingMessages {};
|
||||
|
||||
MessageBoxException::MessageBoxException( const TranslatableString &caption_ )
|
||||
: caption{ caption_ }
|
||||
MessageBoxException::MessageBoxException(
|
||||
ExceptionType exceptionType_, const TranslatableString& caption_)
|
||||
: caption { caption_ }
|
||||
, exceptionType { exceptionType_ }
|
||||
{
|
||||
if (!caption.empty())
|
||||
wxAtomicInc( sOutstandingMessages );
|
||||
|
@ -42,6 +44,7 @@ MessageBoxException::MessageBoxException( const MessageBoxException& that )
|
|||
caption = that.caption;
|
||||
moved = that.moved;
|
||||
helpUrl = that.helpUrl;
|
||||
exceptionType = that.exceptionType;
|
||||
that.moved = true;
|
||||
}
|
||||
|
||||
|
@ -73,21 +76,27 @@ void MessageBoxException::DelayedHandlerAction()
|
|||
// give the user no useful added information.
|
||||
|
||||
if ( wxAtomicDec( sOutstandingMessages ) == 0 ) {
|
||||
if (ErrorHelpUrl().IsEmpty())
|
||||
if (exceptionType == ExceptionType::Internal)
|
||||
{
|
||||
ShowExceptionDialog(
|
||||
nullptr,
|
||||
(caption.empty() ? AudacityMessageBoxCaptionStr() : caption),
|
||||
ErrorMessage(), ErrorHelpUrl());
|
||||
}
|
||||
// We show BadEnvironment and BadUserAction in a similar way
|
||||
else if (ErrorHelpUrl().IsEmpty())
|
||||
{
|
||||
::AudacityMessageBox(
|
||||
ErrorMessage(),
|
||||
(caption.empty() ? AudacityMessageBoxCaptionStr() : caption),
|
||||
wxICON_ERROR
|
||||
);
|
||||
wxICON_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowErrorDialog(
|
||||
nullptr,
|
||||
(caption.empty() ? AudacityMessageBoxCaptionStr() : caption),
|
||||
ErrorMessage(),
|
||||
ErrorHelpUrl());
|
||||
ErrorMessage(), ErrorHelpUrl());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,14 @@
|
|||
|
||||
#include "Internat.h"
|
||||
|
||||
//! A type of an exception
|
||||
enum class ExceptionType
|
||||
{
|
||||
Internal, //!< Indicates internal failure from Audacity.
|
||||
BadUserAction, //!< Indicates that the user performed an action that is not allowed.
|
||||
BadEnvironment, //!< Indicates problems with environment, such as a full disk
|
||||
};
|
||||
|
||||
//! Base class for exceptions specially processed by the application
|
||||
/*! Objects of this type can be thrown and caught in any thread, stored, and then used by the main
|
||||
thread in later idle time to explain the error condition to the user.
|
||||
|
@ -57,7 +65,8 @@ class AUDACITY_DLL_API MessageBoxException /* not final */
|
|||
protected:
|
||||
//! If default-constructed with empty caption, it makes no message box.
|
||||
explicit MessageBoxException(
|
||||
const TranslatableString &caption = {} //!< Shown in message box's frame; not the actual message
|
||||
ExceptionType exceptionType, //!< Exception type
|
||||
const TranslatableString &caption //!< Shown in message box's frame; not the actual message
|
||||
);
|
||||
~MessageBoxException() override;
|
||||
|
||||
|
@ -69,6 +78,8 @@ protected:
|
|||
|
||||
private:
|
||||
TranslatableString caption; //!< Stored caption
|
||||
ExceptionType exceptionType; //!< Exception type
|
||||
|
||||
mutable bool moved { false }; //!< Whether @c *this has been the source of a copy
|
||||
protected:
|
||||
mutable wxString helpUrl{ "" };
|
||||
|
@ -80,11 +91,12 @@ class AUDACITY_DLL_API SimpleMessageBoxException /* not final */
|
|||
{
|
||||
public:
|
||||
explicit SimpleMessageBoxException(
|
||||
ExceptionType exceptionType, //!< Exception type
|
||||
const TranslatableString &message_, //<! Message to show
|
||||
const TranslatableString &caption = XO("Message"), //<! Short caption in frame around message
|
||||
const wxString &helpUrl_ = "" // Optional URL for help.
|
||||
)
|
||||
: MessageBoxException{ caption }
|
||||
: MessageBoxException { exceptionType, caption }
|
||||
, message{ message_ }
|
||||
{
|
||||
helpUrl = helpUrl_;
|
||||
|
|
|
@ -1463,7 +1463,7 @@ void AudioIO::StartMonitoring( const AudioIOStartStreamOptions &options )
|
|||
if (!success) {
|
||||
auto msg = XO("Error opening recording device.\nError code: %s")
|
||||
.Format( Get()->LastPaErrorString() );
|
||||
ShowErrorDialog( FindProjectFrame( mOwningProject ),
|
||||
ShowExceptionDialog( FindProjectFrame( mOwningProject ),
|
||||
XO("Error"), msg, wxT("Error_opening_sound_device"));
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -494,8 +494,8 @@ void DBConnection::CheckpointThread(sqlite3 *db, const FilePath &fileName)
|
|||
|
||||
// Stop the audio.
|
||||
GuardedCall(
|
||||
[&message] {
|
||||
throw SimpleMessageBoxException{
|
||||
[&message, rc] {
|
||||
throw SimpleMessageBoxException{ rc != SQLITE_FULL ? ExceptionType::Internal : ExceptionType::BadEnvironment,
|
||||
message, XO("Warning"), "Error:_Disk_full_or_not_writable" }; },
|
||||
SimpleGuard<void>{},
|
||||
[this](AudacityException * e) {
|
||||
|
@ -596,7 +596,7 @@ TransactionScope::TransactionScope(
|
|||
mInTrans = TransactionStart(mName);
|
||||
if ( !mInTrans )
|
||||
// To do, improve the message
|
||||
throw SimpleMessageBoxException(
|
||||
throw SimpleMessageBoxException( ExceptionType::Internal,
|
||||
XO("Database error. Sorry, but we don't have more details."),
|
||||
XO("Warning"),
|
||||
"Error:_Disk_full_or_not_writable"
|
||||
|
|
|
@ -32,7 +32,11 @@ public:
|
|||
const TranslatableString &caption = XO("File Error"), //!< Shown in message box frame, not the main message
|
||||
const wxFileName &renameTarget_ = {} //!< A second file name, only for renaming failure
|
||||
)
|
||||
: MessageBoxException{ caption }
|
||||
// DV: We consider a FileException to be internal for now.
|
||||
// We used to have some odd cases related to the read-only folder in 3.0.0,
|
||||
// so it is good to have a full picture here.
|
||||
// In case we see to many - we will tweak this behavior in the next release.
|
||||
: MessageBoxException{ ExceptionType::Internal, caption }
|
||||
, cause{ cause_ }, fileName{ fileName_ }, renameTarget{ renameTarget_ }
|
||||
{}
|
||||
|
||||
|
|
|
@ -23,7 +23,9 @@
|
|||
class AUDACITY_DLL_API InconsistencyException final : public MessageBoxException
|
||||
{
|
||||
public:
|
||||
InconsistencyException() {}
|
||||
InconsistencyException ()
|
||||
: MessageBoxException{ ExceptionType::Internal, XO ("Internal Error") }
|
||||
{}
|
||||
|
||||
//! Don't call this directly but use @ref CONSTRUCT_INCONSISTENCY_EXCEPTION or @ref THROW_INCONSISTENCY_EXCEPTION
|
||||
explicit InconsistencyException(
|
||||
|
@ -31,8 +33,8 @@ public:
|
|||
const char *f, //!< function name supplied by preprocessor
|
||||
unsigned l //!< line number supplied by preprocessor
|
||||
)
|
||||
: MessageBoxException{ XO("Internal Error") }
|
||||
, func { fn }, file { f }, line { l }
|
||||
: MessageBoxException { ExceptionType::Internal, XO("Internal Error") }
|
||||
, func { fn }, file { f }, line { l }
|
||||
{}
|
||||
|
||||
InconsistencyException(InconsistencyException&& that)
|
||||
|
|
|
@ -264,7 +264,7 @@ int ProjectAudioManager::PlayPlayRegion(const SelectedRegion &selectedRegion,
|
|||
auto &window = GetProjectFrame( mProject );
|
||||
window.CallAfter( [&]{
|
||||
// Show error message if stream could not be opened
|
||||
ShowErrorDialog(&window, XO("Error"),
|
||||
ShowExceptionDialog(&window, XO("Error"),
|
||||
XO("Error opening sound device.\nTry changing the audio host, playback device and the project sample rate."),
|
||||
wxT("Error_opening_sound_device"));
|
||||
});
|
||||
|
@ -757,7 +757,7 @@ bool ProjectAudioManager::DoRecord(AudacityProject &project,
|
|||
// Show error message if stream could not be opened
|
||||
auto msg = XO("Error opening recording device.\nError code: %s")
|
||||
.Format( gAudioIO->LastPaErrorString() );
|
||||
ShowErrorDialog(&GetProjectFrame( mProject ),
|
||||
ShowExceptionDialog(&GetProjectFrame( mProject ),
|
||||
XO("Error"), msg, wxT("Error_opening_sound_device"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -307,6 +307,7 @@ DBConnection &ProjectFileIO::GetConnection()
|
|||
{
|
||||
throw SimpleMessageBoxException
|
||||
{
|
||||
ExceptionType::Internal,
|
||||
XO("Failed to open the project's database"),
|
||||
XO("Warning"),
|
||||
"Error:_Disk_full_or_not_writable"
|
||||
|
|
|
@ -341,7 +341,7 @@ bool ProjectFileManager::DoSave(const FilePath & fileName, const bool fromSaveAs
|
|||
// Show this error only if we didn't fail reconnection in SaveProject
|
||||
// REVIEW: Could HasConnection() be true but SaveProject() still have failed?
|
||||
if (!projectFileIO.HasConnection())
|
||||
ShowErrorDialog(
|
||||
ShowExceptionDialog(
|
||||
&window,
|
||||
XO("Error Saving Project"),
|
||||
FileException::WriteFailureMessage(fileName),
|
||||
|
@ -770,7 +770,7 @@ bool ProjectFileManager::OpenNewProject()
|
|||
bool bOK = OpenProject();
|
||||
if( !bOK )
|
||||
{
|
||||
ShowErrorDialog(
|
||||
ShowExceptionDialog(
|
||||
nullptr,
|
||||
XO("Can't open new empty project"),
|
||||
XO("Error opening a new empty project"),
|
||||
|
|
|
@ -79,6 +79,7 @@ namespace {
|
|||
{
|
||||
if ( !projectFileIO.AutoSave() )
|
||||
throw SimpleMessageBoxException{
|
||||
ExceptionType::Internal,
|
||||
XO("Automatic database backup failed."),
|
||||
XO("Warning"),
|
||||
"Error:_Disk_full_or_not_writable"
|
||||
|
|
|
@ -341,6 +341,7 @@ DBConnection *SqliteSampleBlock::Conn() const
|
|||
if (!pConnection) {
|
||||
throw SimpleMessageBoxException
|
||||
{
|
||||
ExceptionType::Internal,
|
||||
XO("Connection to project file is null"),
|
||||
XO("Warning"),
|
||||
"Error:_Disk_full_or_not_writable"
|
||||
|
|
|
@ -1739,6 +1739,7 @@ void WaveClip::Resample(int rate, ProgressDialog *progress)
|
|||
|
||||
if (error)
|
||||
throw SimpleMessageBoxException{
|
||||
ExceptionType::Internal,
|
||||
XO("Resampling failed."),
|
||||
XO("Warning"),
|
||||
"Error:_Resampling"
|
||||
|
|
|
@ -1284,6 +1284,7 @@ void WaveTrack::Paste(double t0, const Track *src)
|
|||
// Strong-guarantee in case of this path
|
||||
// not that it matters.
|
||||
throw SimpleMessageBoxException{
|
||||
ExceptionType::BadUserAction,
|
||||
XO("There is not enough room available to paste the selection"),
|
||||
XO("Warning"),
|
||||
"Error:_Insufficient_space_in_track"
|
||||
|
@ -1306,6 +1307,7 @@ void WaveTrack::Paste(double t0, const Track *src)
|
|||
// Strong-guarantee in case of this path
|
||||
// not that it matters.
|
||||
throw SimpleMessageBoxException{
|
||||
ExceptionType::BadUserAction,
|
||||
XO("There is not enough room available to paste the selection"),
|
||||
XO("Warning"),
|
||||
"Error:_Insufficient_space_in_track"
|
||||
|
@ -2422,6 +2424,7 @@ void WaveTrack::ExpandCutLine(double cutLinePosition, double* cutlineStart,
|
|||
clip->GetEndTime() + end - start > clip2->GetStartTime())
|
||||
// Strong-guarantee in case of this path
|
||||
throw SimpleMessageBoxException{
|
||||
ExceptionType::BadUserAction,
|
||||
XO("There is not enough room available to expand the cut line"),
|
||||
XO("Warning"),
|
||||
"Error:_Insufficient_space_in_track"
|
||||
|
|
|
@ -2468,7 +2468,7 @@ void Effect::Preview(bool dryOnly)
|
|||
}
|
||||
}
|
||||
else {
|
||||
ShowErrorDialog(FocusDialog, XO("Error"),
|
||||
ShowExceptionDialog(FocusDialog, XO("Error"),
|
||||
XO("Error opening sound device.\nTry changing the audio host, playback device and the project sample rate."),
|
||||
wxT("Error_opening_sound_device"));
|
||||
}
|
||||
|
|
|
@ -1519,7 +1519,7 @@ void ShowExportErrorDialog(wxString ErrorCode,
|
|||
TranslatableString message,
|
||||
const TranslatableString& caption)
|
||||
{
|
||||
ShowErrorDialog(nullptr,
|
||||
ShowExceptionDialog(nullptr,
|
||||
caption,
|
||||
message.Format( ErrorCode ),
|
||||
"Error:_Unable_to_export" // URL.
|
||||
|
|
|
@ -210,6 +210,7 @@ static void Extract(bool bits16,
|
|||
|
||||
if( dataSizeIn < 1 )
|
||||
throw SimpleMessageBoxException{
|
||||
ExceptionType::BadUserAction,
|
||||
XO("Bad data size. Could not import audio"),
|
||||
XO("Warning"),
|
||||
"Error:_Importing_raw_audio"
|
||||
|
|
|
@ -447,6 +447,7 @@ void OnPaste(const CommandContext &context)
|
|||
// Throw, so that any previous changes to the project in this loop
|
||||
// are discarded.
|
||||
throw SimpleMessageBoxException{
|
||||
ExceptionType::BadUserAction,
|
||||
XO("Pasting one type of track into another is not allowed."),
|
||||
XO("Warning"),
|
||||
"Error:_Copying_or_Pasting"
|
||||
|
@ -477,6 +478,7 @@ void OnPaste(const CommandContext &context)
|
|||
// Throw, so that any previous changes to the project in this
|
||||
// loop are discarded.
|
||||
throw SimpleMessageBoxException{
|
||||
ExceptionType::BadUserAction,
|
||||
XO("Copying stereo audio into a mono track is not allowed."),
|
||||
XO("Warning"),
|
||||
"Error:_Copying_or_Pasting"
|
||||
|
|
|
@ -699,7 +699,7 @@ namespace {
|
|||
[[noreturn]] void MigrationFailure() {
|
||||
// Tracks may be in an inconsistent state; throw to the application
|
||||
// handler which restores consistency from undo history
|
||||
throw SimpleMessageBoxException{
|
||||
throw SimpleMessageBoxException{ ExceptionType::Internal,
|
||||
XO("Could not shift between tracks")};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue