Skip to content

Commit d34fd61

Browse files
committed
RDX v1.0.5; upload error handling
1 parent 49dd938 commit d34fd61

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

SmartImage.Rdx/Program.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,29 @@ public static async Task<int> Main(string[] args)
8383
c.PropagateExceptions();
8484
var helpProvider = new CustomHelpProvider(c.Settings);
8585
c.SetHelpProvider(helpProvider);
86+
8687
c.AddCommand<IntegrationCommand>("integrate")
8788
.WithDescription("Configure system integration such as context menu");
8889
});
8990

90-
try {
91-
var x = await app.RunAsync(args);
91+
int x = SearchCommand.EC_OK;
9292

93-
if (x != SearchCommand.EC_OK) {
94-
AConsole.Confirm("Press any key to continue");
95-
}
93+
try {
94+
x = await app.RunAsync(args);
9695

97-
return x;
9896
}
9997
catch (Exception e) {
10098
AConsole.WriteException(e);
101-
return SearchCommand.EC_ERROR;
99+
x = SearchCommand.EC_ERROR;
102100
}
101+
finally {
102+
103+
if (x != SearchCommand.EC_OK) {
104+
AConsole.Confirm("Press any key to continue");
105+
}
106+
}
107+
108+
return x;
103109
}
104110

105111
}

SmartImage.Rdx/SearchCommand.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ internal sealed class SearchCommand : AsyncCommand<SearchCommandSettings>, IDisp
6565
public const int EC_OK = 0;
6666

6767
public static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
68-
public static readonly Version Version = Assembly.GetName().Version;
68+
public static readonly Version Version = Assembly.GetName().Version;
6969

7070
public SearchCommand()
7171
{
@@ -92,16 +92,19 @@ public SearchCommand()
9292

9393
#region
9494

95-
private async Task SetupSearchAsync(ProgressContext ctx)
95+
private async Task<bool> SetupSearchAsync(ProgressContext ctx)
9696
{
9797
var p = ctx.AddTask("Creating query");
9898
p.IsIndeterminate = true;
99+
bool ok = true;
99100

100101
Query = await SearchQuery.TryCreateAsync(m_scs.Query);
101102

102103
if (Query == SearchQuery.Null) {
103-
throw new SmartImageException($"Could not create query"); //todo
104+
// throw new SmartImageException($"Could not create query"); //todo
104105

106+
ok = false;
107+
goto ret;
105108
}
106109

107110
p.Increment(COMPLETE / 2);
@@ -112,10 +115,15 @@ private async Task SetupSearchAsync(ProgressContext ctx)
112115
var url = await Query.UploadAsync();
113116

114117
if (url == null) {
115-
throw new SmartImageException("Could not upload query"); //todo
118+
// throw new SmartImageException("Could not upload query"); //todo
119+
ok = false;
120+
goto ret;
116121
}
117122

118123
p.Increment(COMPLETE / 2);
124+
125+
ret:
126+
return ok;
119127
}
120128

121129
private async Task InitConfigAsync([CBN] object c)
@@ -294,11 +302,17 @@ public override async Task<int> ExecuteAsync(CommandContext context, SearchComma
294302

295303
var task = AConsole.Progress()
296304
.AutoRefresh(true)
297-
.StartAsync(SetupSearchAsync)
298-
.ContinueWith(InitConfigAsync);
305+
.StartAsync(SetupSearchAsync);
299306

300307
try {
301-
await task;
308+
var ok = await task;
309+
310+
if (ok) {
311+
await InitConfigAsync(ok);
312+
}
313+
else {
314+
throw new SmartImageException("Could not upload query");
315+
}
302316
}
303317
catch (Exception e) {
304318
AConsole.WriteException(e);

0 commit comments

Comments
 (0)