3

继我与 Erlang 和 ErlyDB 的冒险之后。我正在尝试让 ErlyDB 与BeepBeep一起工作

在 BeepBeep 环境之外运行时,我的 ErlyDB 设置可以正常工作(请参阅调试 ErlyDB 和 MySQL)。我基本上已经采用了工作代码并试图让它在 BeepBeep 中运行。

我的控制器中有以下代码:

handle_request("index",[]) ->
  erlydb:start(mysql,Database),
  erlydb:code_gen(["thing.erl"],mysql), 
  NewThing = thing:new_with([{name, "name"},{value, "value"}]),
  thing:save(NewThing),
  {render,"home/index.html",[{data,"Hello World!"}]};

当我调用 URL 时,响应输出“服务器错误”。没有报告其他错误或异常信息。

我尝试将调用包装在 try/catch 中以查看是否存在潜在错误 - 调用thing:new_with()肯定存在异常,但没有更多信息可用。

堆栈跟踪报告:

{thing,new,[["name","value"]]}
{home_controller,create,1}
{home_controller,handle_request,3}
{beepbeep,process_request,4}
{test_web,loop,1}
{mochiweb_http,headers,4}
{proc_lib,init_p_do_apply,3}
4

1 回答 1

2

使用模式匹配来断言事情符合对 thing:new/1 的调用:

ok = erlydb:start(mysql,Database),
ok = erlydb:code_gen(["thing.erl"],mysql), 

您只包括堆栈跟踪,同时查看异常消息。我怀疑错误是你得到一个'undef'异常。但请检查是否如此。堆栈跟踪中的第一行表明使用 ["name", "value"] 作为参数调用 thing:new/1 存在问题。

有点奇怪的是,您显示了一个未按照{home_controller,create,1}堆栈跟踪调用 home_controller:create/1 的 handle_request 子句。你的 handle_request/2 函数中的其他子句是什么样的?

于 2009-08-10T14:20:55.670 回答