3

Custom error lose custom properties

What steps will reproduce the problem:

create function

CREATE OR REPLACE FUNCTION public.utils ()
RETURNS void AS
$body$

this.dbError = function(message){
    this.message = (message || '');
};
dbError.prototype = Error.prototype;

$body$
LANGUAGE 'plv8'
VOLATILE
RETURNS NULL ON NULL INPUT
SECURITY DEFINER
COST 100;

create trigger function

CREATE OR REPLACE FUNCTION public.test_trigger func ()
RETURNS trigger AS
$body$

var fn = plv8.find_function('public.utils');
fn();

var err = new dbError('this is a dbError');
err.someProp = 'lalala';
throw err;

return NEW;
$body$
LANGUAGE 'plv8'
VOLATILE
CALLED ON NULL INPUT
SECURITY DEFINER
COST 100;

set this trigger on any table on insteadof event and try to execute it

DO $$ 
plv8.find_function('public.utils')();
try{
  plv8.execute('insert into Temp (field) value ($1)', [100]);
} catch(ex){
  plv8.elog(NOTICE, ex instanceof dbError);
  plv8.elog(NOTICE, ex.message);
  plv8.elog(NOTICE, ex.someProp);
}
$$ LANGUAGE plv8;

we will see

true
this is a dbError
undefined

What is the expected output?

true
this is a dbError
lalala

if I do this in one scope - I get right result

DO $$ 
this.dbError = function(message){
    this.message = (message || '');
};
dbError.prototype = Error.prototype;

try{
  var err = new dbError('this is a dbError');
  err.someProp = 'lalala';
  throw err;
} catch(ex){
  plv8.elog(NOTICE, ex instanceof dbError);
  plv8.elog(NOTICE, ex.message);
  plv8.elog(NOTICE, ex.someProp);
}

$$ LANGUAGE plv8;

the result:

true
this is a dbError
lalala
user2627000
  • 317
  • 1
  • 2
  • 10
  • What exactly do you mean with "*Custom error loose properties*". Why are the properties "loose"? (or did you mean "lose" which is something different than "loose"?) –  Jan 29 '14 at 13:05
  • sorry, lose of course) – user2627000 Jan 29 '14 at 13:57

0 Answers0