Updating occured error details into current database within undo'ed transaction

huangapple go评论78阅读模式
英文:

Updating occured error details into current database within undo'ed transaction

问题

我有一个简单的数据库,其中包含几个表格,还有一个用于运行时错误的表格。想法是将所有发生的运行时错误保存到这个表格中。以下演示了我的用例:

test1.p:

BLOCK-LEVEL ON ERROR UNDO, THROW.

/* Some code which throws error */
RUN errorThrowingProcedure.

/* Catch any errors */
CATCH oError AS Progress.Lang.Error:

    /* Write error to current database */
    DEF BUFFER Errors_B1 FOR Errors.
    CREATE Errors_B1.
    ASSIGN Errors_B1.DateTimeTz = NOW
           Errors_B1.ProgramName = PROGRAM-NAME(1)
           Errors_B1.Message     = oError:GetMessage(1).

    /* Rethrow error to upper level */
    UNDO, THROW oError.
END.

这不起作用是因为错误'重新抛出',这将UNDO数据库更改。

我不想将错误保存到NO-UNDO变量或TEMP-TABLE中,然后稍后进行更新。我也不想根据正在进行的事务在多个地方传播这种错误逻辑。

我在考虑以下方式来处理:

test2.p:

BLOCK-LEVEL ON ERROR UNDO, THROW.

/* Some code which throws error */
RUN errorThrowingProcedure.

/* Catch any errors */
CATCH oError AS Progress.Lang.Error:

    DEF VAR cCommandLine AS CHAR NO-UNDO.
    DEF VAR cApplication AS CHAR NO-UNDO INIT "C:\Progress91E\bin\prowin32.exe".
    DEF VAR cDatabase    AS CHAR NO-UNDO INIT "MyDatabase".
    DEF VAR cParams      AS CHAR NO-UNDO.
    DEF VAR cProcedure   AS CHAR NO-UNDO INIT "C:\WRK91E\CreateError.p".

    /* Params: 'Errors.DateTimeTz', 'Errors.ProgramName' and 'Errors.Message' */
    cParams = SUBST("&1, &2, &3", NOW, PROGRAM-NAME(1), oError:GetMessage(1)).

    cCommandLine = SUBST('&1 &2 -param "&3" -b -p &4', cApplication, cDatabase, cParams, cProcedure).

    /* Write occurred error to database */
    OS-COMMAND NO-WAIT NO-CONSOLE VALUE(cCommandLine) NO-ERROR.

    /* Rethrow error to upper level */
    UNDO, THROW oError.
END.

是否有其他更简单的方法来实现这一点?

如果有另一种更容易或更强大的方式在当前客户端进程内调用新的进度客户端,我就不想依赖于OS-COMMAND。上面的代码也是特定于平台的。我希望能够在所有可能的平台上运行它。

英文:

I have a simple database which contains few tables and also a table for runtime errors. The idea is to save all occurred runtime errors into this table. The following demonstrates my use-case:

test1.p:

BLOCK-LEVEL ON ERROR UNDO, THROW.

/* Some code which throws error */
RUN errorThrowingProcedure.

/* Catch any errors */
CATCH oError AS Progress.Lang.Error:
    
    /* Write error to current database */
    DEF BUFFER Errors_B1 FOR Errors.
    CREATE Errors_B1.
    ASSIGN Errors_B1.DateTimeTz = NOW
           Errors_B1.ProgramName = PROGRAM-NAME(1)
           Errors_B1.Message     = oError:GetMessage(1).
    
    /* Rethrow error to upper level */
    UNDO, THROW oError.
END.

This doesn't work because of the error 'rethrow', which will UNDO the database changes.

I don't want to save the error to some NO-UNDO variables or TEMP-TABLEs and do the update later. I also don't want to spread this kind of error logic to multiple places depending on the ongoing transactions.

I was thinking about doing it the following way:

test2.p:

BLOCK-LEVEL ON ERROR UNDO, THROW.

/* Some code which throws error */
RUN errorThrowingProcedure.

/* Catch any errors */
CATCH oError AS Progress.Lang.Error:
    
    DEF VAR cCommandLine AS CHAR NO-UNDO.
    DEF VAR cApplication AS CHAR NO-UNDO INIT "C:\Progress91E\bin\prowin32.exe".
    DEF VAR cDatabase    AS CHAR NO-UNDO INIT "MyDatabase".
    DEF VAR cParams      AS CHAR NO-UNDO.
    DEF VAR cProcedure   AS CHAR NO-UNDO INIT "C:\WRK91E\CreateError.p".

    /* Params: 'Errors.DateTimeTz', 'Errors.ProgramName' and 'Errors.Message' */
    cParams = SUBST("&1, &2, &3", NOW, PROGRAM-NAME(1), oError:GetMessage(1)).

    cCommandLine = SUBST('&1 &2 -param "&3" -b -p &4', cApplication, cDatabase, cParams, cProcedure).

    /* Write occured error to database */
    OS-COMMAND NO-WAIT NO-CONSOLE VALUE(cCommandLine) NO-ERROR.
    
    /* Rethrow error to upper level */
    UNDO, THROW oError.
END.

Is there's any other simpler way to achieve this?

I wouldn't want to rely on OS-COMMAND if there's another easier or more robust way to invoke a new progress client within the current client process. The code above is also platform specific. I'd like to make it work on all possible platforms..

答案1

得分: 1

启动另一个 OpenEdge 批处理客户端似乎很昂贵。

您是否可以访问 OpenEdge AppServer?AppServer 不会与客户端共享事务。

考虑记录到文件吗?

英文:

Launching another OpenEdge batch client seems expensive.

Do you have access to an OpenEdge AppServer? AppServer's don't share the transaction with the client.

How about logging to file?

huangapple
  • 本文由 发表于 2023年6月26日 16:55:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76555095.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定