summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2010-02-05 14:47:59 +0100
committerTomas Bzatek <tbzatek@redhat.com>2010-02-05 14:47:59 +0100
commit8f1ad519dd5ae1d17f625044bf18c3d8e77acea5 (patch)
treedaf77dd7bb5c29fafbfc2cb8aeacc72a22d49a0c
parentbe965b1ba6d05d188ccf4eb5b9f93ca56209161c (diff)
downloadtuxcmd-8f1ad519dd5ae1d17f625044bf18c3d8e77acea5.tar.xz
Report exceptions coming from VFS
-rw-r--r--UError.pas12
-rw-r--r--vfs/UVFSCore.pas118
2 files changed, 90 insertions, 40 deletions
diff --git a/UError.pas b/UError.pas
index 57250a8..6734367 100644
--- a/UError.pas
+++ b/UError.pas
@@ -21,7 +21,7 @@ unit UError;
interface
-uses glib2, gtk2, Classes, ULibc, GTKForms;
+uses glib2, gtk2, Classes, SysUtils, ULibc, GTKForms;
// Ported from gioerror.h
@@ -68,11 +68,13 @@ function G_IO_ERROR: TGQuark;
function g_io_error_from_errno(err_no: gint): GIOErrorEnum;
+procedure g_set_error_from_exception(Error: PPGError; E: Exception);
+
procedure ShowError(Parent: TCustomGTKForm; const Text: string; Error: PGError);
implementation
-uses SysUtils, UCoreUtils, UGnome;
+uses UCoreUtils, UGnome;
(********************************************************************************************************************************)
@@ -115,6 +117,12 @@ end;
(********************************************************************************************************************************)
+procedure g_set_error_from_exception(Error: PPGError; E: Exception);
+begin
+ g_set_error(Error, G_IO_ERROR, integer(G_IO_ERROR_FAILED), 'Exception raised: %s', PChar(E.Message));
+end;
+
+(********************************************************************************************************************************)
procedure ShowError(Parent: TCustomGTKForm; const Text: string; Error: PGError);
var Dialog: PGtkWidget;
error_str: PChar;
diff --git a/vfs/UVFSCore.pas b/vfs/UVFSCore.pas
index d875b83..0ce7e1f 100644
--- a/vfs/UVFSCore.pas
+++ b/vfs/UVFSCore.pas
@@ -382,29 +382,43 @@ end;
function TVFSEngine.VFSOpenURI(const URI: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer; Error: PPGError): boolean;
begin
Result := False;
- if (FGlobs <> nil) and (@FSourcePlugin.FVFSOpenURI <> nil) then begin
- if @FSourcePlugin.FVFSSetCallbacks <> nil then
- FSourcePlugin.FVFSSetCallbacks(FGlobs, AskQuestionCallback, AskPasswordCallback, ProgressCallback, CallbackData);
- Result := FSourcePlugin.FVFSOpenURI(FGlobs, PChar(URI), Error);
- FArchiveMode := False;
- FArchivePath := '';
- if @FSourcePlugin.FVFSSetCallbacks <> nil then
- FSourcePlugin.FVFSSetCallbacks(FGlobs, nil, nil, nil, nil);
+ try
+ if (FGlobs <> nil) and (@FSourcePlugin.FVFSOpenURI <> nil) then begin
+ if @FSourcePlugin.FVFSSetCallbacks <> nil then
+ FSourcePlugin.FVFSSetCallbacks(FGlobs, AskQuestionCallback, AskPasswordCallback, ProgressCallback, CallbackData);
+ Result := FSourcePlugin.FVFSOpenURI(FGlobs, PChar(URI), Error);
+ FArchiveMode := False;
+ FArchivePath := '';
+ if @FSourcePlugin.FVFSSetCallbacks <> nil then
+ FSourcePlugin.FVFSSetCallbacks(FGlobs, nil, nil, nil, nil);
+ end;
+ except
+ on E: Exception do begin
+ g_set_error_from_exception(Error, E);
+ Result := False;
+ end;
end;
end;
function TVFSEngine.VFSOpenEx(const OpenFile: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer; Error: PPGError): boolean;
begin
Result := False;
- if (FGlobs <> nil) and (@FSourcePlugin.FVFSOpenArchive <> nil) then begin
- if @FSourcePlugin.FVFSSetCallbacks <> nil then
- FSourcePlugin.FVFSSetCallbacks(FGlobs, AskQuestionCallback, AskPasswordCallback, ProgressCallback, CallbackData);
- Result := FSourcePlugin.FVFSOpenArchive(FGlobs, PChar(OpenFile), Error);
- FArchiveMode := True;
- if Result then FArchivePath := OpenFile
- else FArchivePath := '';
- if @FSourcePlugin.FVFSSetCallbacks <> nil then
- FSourcePlugin.FVFSSetCallbacks(FGlobs, nil, nil, nil, nil);
+ try
+ if (FGlobs <> nil) and (@FSourcePlugin.FVFSOpenArchive <> nil) then begin
+ if @FSourcePlugin.FVFSSetCallbacks <> nil then
+ FSourcePlugin.FVFSSetCallbacks(FGlobs, AskQuestionCallback, AskPasswordCallback, ProgressCallback, CallbackData);
+ Result := FSourcePlugin.FVFSOpenArchive(FGlobs, PChar(OpenFile), Error);
+ FArchiveMode := True;
+ if Result then FArchivePath := OpenFile
+ else FArchivePath := '';
+ if @FSourcePlugin.FVFSSetCallbacks <> nil then
+ FSourcePlugin.FVFSSetCallbacks(FGlobs, nil, nil, nil, nil);
+ end;
+ except
+ on E: Exception do begin
+ g_set_error_from_exception(Error, E);
+ Result := False;
+ end;
end;
end;
@@ -487,8 +501,11 @@ begin
real_libc_free(P);
FSourcePlugin.FVFSListClose(FGlobs, nil);
except
- on E: Exception do
+ on E: Exception do begin
DebugMsg(['^^VFS (EE): GetListing: Exception: ', E.Message]);
+ g_set_error_from_exception(Error, E);
+ Result := False;
+ end;
end;
BreakProcessingType := 0;
DebugMsg(['^^VFS (II): GetListing end.']);
@@ -513,8 +530,11 @@ begin
if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
real_libc_free(P);
except
- on E: Exception do
+ on E: Exception do begin
DebugMsg(['^^VFS (EE): GetFileInfo: Exception: ', E.Message]);
+ g_set_error_from_exception(Error, E);
+ Result := nil;
+ end;
end;
DebugMsg(['^^VFS (II): GetFileInfo end.']);
end;
@@ -586,19 +606,31 @@ begin
try
Result := FSourcePlugin.FVFSChangeDir(FGlobs, PChar(NewPath), Error);
except
- on E: Exception do DebugMsg(['^^VFS (EE): ChangeDir: Exception: ', E.Message]);
+ on E: Exception do begin
+ DebugMsg(['^^VFS (EE): ChangeDir: Exception: ', E.Message]);
+ g_set_error_from_exception(Error, E);
+ Result := False;
+ end;
end;
end;
function TVFSEngine.ChangeDirEx(const NewPath: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer; Error: PPGError): boolean;
begin
Result := False;
- if (FGlobs <> nil) and (@FSourcePlugin.FVFSChangeDir <> nil) then begin
- if @FSourcePlugin.FVFSSetCallbacks <> nil then
- FSourcePlugin.FVFSSetCallbacks(FGlobs, AskQuestionCallback, AskPasswordCallback, ProgressCallback, CallbackData);
- Result := ChangeDir(NewPath, Error);
- if @FSourcePlugin.FVFSSetCallbacks <> nil then
- FSourcePlugin.FVFSSetCallbacks(FGlobs, nil, nil, nil, nil);
+ try
+ if (FGlobs <> nil) and (@FSourcePlugin.FVFSChangeDir <> nil) then begin
+ if @FSourcePlugin.FVFSSetCallbacks <> nil then
+ FSourcePlugin.FVFSSetCallbacks(FGlobs, AskQuestionCallback, AskPasswordCallback, ProgressCallback, CallbackData);
+ Result := ChangeDir(NewPath, Error);
+ if @FSourcePlugin.FVFSSetCallbacks <> nil then
+ FSourcePlugin.FVFSSetCallbacks(FGlobs, nil, nil, nil, nil);
+ end;
+ except
+ on E: Exception do begin
+ DebugMsg(['^^VFS (EE): ChangeDirEx: Exception: ', E.Message]);
+ g_set_error_from_exception(Error, E);
+ Result := False;
+ end;
end;
end;
@@ -823,7 +855,11 @@ begin
try
Error := nil;
if @FSourcePlugin.FVFSCopyToLocal <> nil then
- Result := FSourcePlugin.FVFSCopyToLocal(FGlobs, PChar(SourceFile), PChar(DestFile), Append, @Error)
+ try
+ Result := FSourcePlugin.FVFSCopyToLocal(FGlobs, PChar(SourceFile), PChar(DestFile), Append, @Error)
+ except
+ on E: Exception do g_set_error_from_exception(@Error, E);
+ end
else
g_set_error(@Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'VFSCopyToLocal not supported by the VFS module.');
if Error <> nil then begin
@@ -834,10 +870,7 @@ begin
g_error_free(Error);
end;
except
- on E: Exception do begin
- DebugMsg(['*** Exception raised in TVFSEngine.CopyFileOutEx(SourceFile=', SourceFile, ', DestFile=', DestFile, ', Append=', Append,'): (', E.ClassName, '): ', E.Message]);
- Result := False;
- end;
+ on E: Exception do DebugMsg(['*** Exception raised in TVFSEngine.CopyFileOutEx(SourceFile=', SourceFile, ', DestFile=', DestFile, ', Append=', Append,'): (', E.ClassName, '): ', E.Message]);
end;
end;
@@ -849,7 +882,11 @@ begin
try
Error := nil;
if @FSourcePlugin.FVFSCopyFromLocal <> nil then
- Result := FSourcePlugin.FVFSCopyFromLocal(FGlobs, PChar(SourceFile), PChar(DestFile), Append, @Error)
+ try
+ Result := FSourcePlugin.FVFSCopyFromLocal(FGlobs, PChar(SourceFile), PChar(DestFile), Append, @Error)
+ except
+ on E: Exception do g_set_error_from_exception(@Error, E);
+ end
else
g_set_error(@Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'VFSCopyFromLocal not supported by the VFS module.');
if Error <> nil then begin
@@ -860,10 +897,7 @@ begin
g_error_free(Error);
end;
except
- on E: Exception do begin
- DebugMsg(['*** Exception raised in TVFSEngine.CopyFileInEx(SourceFile=', SourceFile, ', DestFile=', DestFile, ', Append=', Append,'): (', E.ClassName, '): ', E.Message]);
- Result := False;
- end;
+ on E: Exception do DebugMsg(['*** Exception raised in TVFSEngine.CopyFileInEx(SourceFile=', SourceFile, ', DestFile=', DestFile, ', Append=', Append,'): (', E.ClassName, '): ', E.Message]);
end;
end;
@@ -879,7 +913,11 @@ begin
if ArchiveMode then begin
Error := nil;
if @FSourcePlugin.FVFSStartCopyOperation <> nil then
- Result := FSourcePlugin.FVFSStartCopyOperation(FGlobs, @Error)
+ try
+ Result := FSourcePlugin.FVFSStartCopyOperation(FGlobs, @Error)
+ except
+ on E: Exception do g_set_error_from_exception(@Error, E);
+ end
else
g_set_error(@Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'VFSStartCopyOperation not supported by the VFS module.');
if Error <> nil then begin
@@ -903,7 +941,11 @@ begin
if ArchiveMode then begin
Error := nil;
if @FSourcePlugin.FVFSStopCopyOperation <> nil then
- Result := FSourcePlugin.FVFSStopCopyOperation(FGlobs, @Error)
+ try
+ Result := FSourcePlugin.FVFSStopCopyOperation(FGlobs, @Error)
+ except
+ on E: Exception do g_set_error_from_exception(@Error, E);
+ end
else
g_set_error(@Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'VFSStopCopyOperation not supported by the VFS module.');
if Error <> nil then begin