mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Add CommandException to abstract cli return codes for errors
This commit is contained in:
parent
c6395b9f35
commit
221d937eec
47 changed files with 538 additions and 572 deletions
|
@ -4,6 +4,9 @@ import net.sourceforge.argparse4j.inf.Namespace;
|
|||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.PlainTextWriterImpl;
|
||||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
import org.asamk.signal.commands.exceptions.IOErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.StickerPackInvalidException;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -23,19 +26,17 @@ public class UploadStickerPackCommand implements LocalCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
|
||||
final var writer = new PlainTextWriterImpl(System.out);
|
||||
var path = new File(ns.getString("path"));
|
||||
|
||||
try {
|
||||
var path = new File(ns.getString("path"));
|
||||
var url = m.uploadStickerPack(path);
|
||||
writer.println("{}", url);
|
||||
return 0;
|
||||
} catch (IOException e) {
|
||||
System.err.println("Upload error: " + e.getMessage());
|
||||
return 3;
|
||||
throw new IOErrorException("Upload error: " + e.getMessage());
|
||||
} catch (StickerPackInvalidException e) {
|
||||
System.err.println("Invalid sticker pack: " + e.getMessage());
|
||||
return 1;
|
||||
throw new UserErrorException("Invalid sticker pack: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue