# HG changeset patch # User jbe # Date 1458340485 -3600 # Node ID 88b47f0dacde875d1a15e538f83d519a93a29059 # Parent e9525f0696076fbd6d4ba032befd3b77e6573ed3 Use ERRCODE and HINT when raising exceptions diff -r e9525f069607 -r 88b47f0dacde core.sql --- a/core.sql Thu Mar 17 03:15:39 2016 +0100 +++ b/core.sql Fri Mar 18 23:34:45 2016 +0100 @@ -1472,10 +1472,9 @@ IF NOT EXISTS ( SELECT NULL FROM "initiative" WHERE "issue_id" = NEW."id" ) THEN - --RAISE 'Cannot create issue without an initial initiative.' USING - -- ERRCODE = 'integrity_constraint_violation', - -- HINT = 'Create issue, initiative, and draft within the same transaction.'; - RAISE EXCEPTION 'Cannot create issue without an initial initiative.'; + RAISE EXCEPTION 'Cannot create issue without an initial initiative.' USING + ERRCODE = 'integrity_constraint_violation', + HINT = 'Create issue, initiative, and draft within the same transaction.'; END IF; RETURN NULL; END; @@ -1528,10 +1527,9 @@ IF NOT EXISTS ( SELECT NULL FROM "draft" WHERE "initiative_id" = NEW."id" ) THEN - --RAISE 'Cannot create initiative without an initial draft.' USING - -- ERRCODE = 'integrity_constraint_violation', - -- HINT = 'Create issue, initiative and draft within the same transaction.'; - RAISE EXCEPTION 'Cannot create initiative without an initial draft.'; + RAISE EXCEPTION 'Cannot create initiative without an initial draft.' USING + ERRCODE = 'integrity_constraint_violation', + HINT = 'Create issue, initiative and draft within the same transaction.'; END IF; RETURN NULL; END; @@ -1584,7 +1582,9 @@ IF NOT EXISTS ( SELECT NULL FROM "opinion" WHERE "suggestion_id" = NEW."id" ) THEN - RAISE EXCEPTION 'Cannot create a suggestion without an opinion.'; + RAISE EXCEPTION 'Cannot create a suggestion without an opinion.' USING + ERRCODE = 'integrity_constraint_violation', + HINT = 'Create suggestion and opinion within the same transaction.'; END IF; RETURN NULL; END; @@ -1737,7 +1737,8 @@ RETURN NULL; -- allows changing of voter comment END IF; END IF; - RAISE EXCEPTION 'Tried to modify data after voting has been closed.'; + RAISE EXCEPTION 'Tried to modify data after voting has been closed.' USING + ERRCODE = 'integrity_constraint_violation'; END IF; RETURN NULL; END; @@ -2848,7 +2849,8 @@ current_setting('transaction_isolation') NOT IN ('repeatable read', 'serializable') THEN - RAISE EXCEPTION 'Insufficient transaction isolation level'; + RAISE EXCEPTION 'Insufficient transaction isolation level' USING + HINT = 'Consider using SET TRANSACTION ISOLATION LEVEL REPEATABLE READ.'; END IF; RETURN; END;