[Webfunds-commits] java/webfunds/sox Errors.java ValueAccount.java
Ian Grigg
iang@cypherpunks.ai
Tue, 18 Jul 2000 18:21:04 -0400 (AST)
iang 00/07/18 18:21:04
Modified: webfunds/sox Errors.java ValueAccount.java
Log:
Particularly noxious bug where the exceptions thrown were the
wrong type. Now that we have a real user of these exceptions
(teller) that relies on the information being accurate, it
behoves to get the SOXWallet and webfunds.sox exceptions
tightened up.
Revision Changes Path
1.15 +6 -6 java/webfunds/sox/Errors.java
Index: Errors.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Errors.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Errors.java 2000/07/16 19:33:39 1.14
+++ Errors.java 2000/07/18 22:21:04 1.15
@@ -1,5 +1,5 @@
/*
- * $Id: Errors.java,v 1.14 2000/07/16 19:33:39 iang Exp $
+ * $Id: Errors.java,v 1.15 2000/07/18 22:21:04 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -140,8 +140,8 @@
}
/**
- * The non OO way of handling errors - get the string.
- * Maybe we should have an exception for each one.
+ * Is this in our recognised block?
+ * Not a complete test, there are some gaps.
*/
public static final boolean isSOXError(int errno)
{
@@ -152,13 +152,13 @@
}
/**
- * The non OO way of handling errors - get the string.
- * Maybe we should have an exception for each one.
+ * The non OO way of handling errors - get the string.
+ * Maybe we should have an exception for each one.
*/
public static final String errorString(int errno)
{
if (!isSOXError(errno))
- return "unknown SOX error";
+ return "unknown error, not in SOX block";
return errors[errno];
}
1.18 +48 -28 java/webfunds/sox/ValueAccount.java
Index: ValueAccount.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/ValueAccount.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ValueAccount.java 2000/07/16 19:35:33 1.17
+++ ValueAccount.java 2000/07/18 22:21:04 1.18
@@ -1,5 +1,5 @@
/*
- * $Id: ValueAccount.java,v 1.17 2000/07/16 19:35:33 iang Exp $
+ * $Id: ValueAccount.java,v 1.18 2000/07/18 22:21:04 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -69,8 +69,12 @@
throw new SOXArgsException(s);
}
+ boolean myDID = false; // user DID being dud is a user error
if (did == null || (did.length() == 0))
+ {
did = "D" + System.currentTimeMillis();
+ myDID = true; // but my DID should be SubAccount error
+ }
String num = "" + reqNo++;
DepositRequest req = new DepositRequest(num, acct.getId(),
payment, did, desc.getBytes());
@@ -89,20 +93,24 @@
}
req.setSignature(sig);
- return doDepositGetMail(req, false);
+ return doDepositGetMail(req, false, myDID);
}
/**
- * Convert the deposit request into a receipt.
- * This catches a number of local snafus that are reported
- * by the issuer, corrects them, and retries.
- * As there are a number of issuers within this account,
- * it is hard to keep track of who has registered where
- * (bearing in mind that there are few issuers, and many contracts).
- * So, we do it by feedback.
+ * Convert the deposit request into a receipt.
+ * This catches a number of local snafus that are reported
+ * by the issuer, corrects them, and retries.
+ * As there are a number of issuers within this account,
+ * it is hard to keep track of who has registered where
+ * (bearing in mind that there are few issuers, and many contracts).
+ * So, we do it by feedback.
+ *
+ * @param retry true if this call is recursive
+ * @param myDID true if DID locally generated (and should be perfect)
*/
- protected MailItem[] doDepositGetMail(DepositRequest req, boolean retry)
+ protected MailItem[] doDepositGetMail(DepositRequest req,
+ boolean retry, boolean myDID)
throws SOXSubAccountException, SOXDepositException, SOXLaterException,
SOXKeyException
{
@@ -123,24 +131,36 @@
else if (!retry && err == Errors.ERROR_NOT_GOOD_KHID)
{
- System.err.println("Hmm, I'm not registered. Trying ...");
+ logmsg("Hmm, I'm not registered. Trying ...");
status &= ~REGISTERED; // turn off that flag (optional)
register(); // do the register (again!?!)
- mis = doDepositGetMail(req, true); // try deposit again
- System.err.println("... Yep, that worked!");
+ mis = doDepositGetMail(req, true, myDID); // try deposit again
+ logmsg("... Yep, that worked!");
}
-// these aren't appropriate for a cancel!
+ /*
+ * These errors could be conceivably caused naturally
+ * by upper layers as caller failures beyond the control
+ * of this package. Or something.
+ */
else if (
(err == Errors.ERROR_NO_FUNDS) ||
(err == Errors.ERROR_CANCELLED) ||
(err == Errors.ERROR_TOO_OLD) ||
- (err == Errors.ERROR_UNKNOWN_SOURCE)
+ (err == Errors.ERROR_TOO_YOUNG) ||
+ (err == Errors.ERROR_UNKNOWN_SOURCE) ||
+ (err == Errors.ERROR_ILLEGAL_DEBIT) ||
+ (err == Errors.ERROR_ALREADY) ||
+ ( (err == Errors.ERROR_DEP_ALREADY) && !myDID )
)
throw new SOXDepositException(err, txt);
+ /*
+ * Anything else should never happen,
+ * if it does, fix it or move it above.
+ */
else
- throw new SOXSubAccountException("Failed (" + err + ") " + txt);
+ throw new SOXSubAccountException(err, "Deposit Failure: " + txt);
status |= ACTIVE;
return mis ;
@@ -296,9 +316,9 @@
}
/**
- * Do the cancel and look at the error.
- * Like doDepositGetMail() but handles cancel errors.
- *
+ * Do the cancel and look at the error.
+ * Like doDepositGetMail() but handles cancel errors, which should
+ * be far fewer as it is all locally organised.
*/
protected MailItem[] doCancelGetMail(DepositRequest req)
throws SOXSubAccountException, SOXDepositException, SOXLaterException
@@ -327,15 +347,15 @@
else if (err == Errors.ERROR_LATER)
throw new SOXLaterException(err, txt);
- else if (
- (err == Errors.ERROR_NO_FUNDS) ||
- (err == Errors.ERROR_TOO_OLD) ||
- (err == Errors.ERROR_UNKNOWN_SOURCE)
- )
- throw new SOXDepositException(err, txt);
+ // else if (
+ // no funds on cancel? (err == Errors.ERROR_NO_FUNDS) ||
+ // i just wrote this? (err == Errors.ERROR_TOO_OLD) ||
+ // i am the source? (err == Errors.ERROR_UNKNOWN_SOURCE)
+ // )
+ // throw new SOXDepositException(err, txt);
else
- throw new SOXSubAccountException("Failed (" + err + ") " + txt);
+ throw new SOXSubAccountException(err, "Cancel Failure: " + txt);
status |= ACTIVE;
return reply.getMailItems();
@@ -453,7 +473,7 @@
payment.setSignature(sig);
boolean signed = payment.verify(acct.getPublicKey());
- System.err.println("PAYMENT IS SIGNED: " + signed);
+ logmsg("PAYMENT IS SIGNED: " + signed);
return payment;
}
@@ -496,7 +516,7 @@
payment.setSignature(sig);
boolean signed = payment.verify(acct.getPublicKey());
- System.err.println("PAYMENT IS SIGNED: " + signed);
+ logmsg("PAYMENT IS SIGNED: " + signed);
return payment;
}