对,一直不变的表用 enum 没问题。但它会强制走 ctfe,所以 parseServices 里的每条路径都得能在编译期跑。smtp 25 那行进了你的错误分支,而 stderr.writeln 在那里跑不了。
改成 throw 一个 Exception,或者用 assert(0, msg)。编译器会把这条消息当作构建错误打印出来,正好是你想要的。
ci.sh 是另一回事。ldc2 做 import() 需要 -J.。dub 会根据 stringImportPaths 帮你传,直接用 ldc2 就不会。
我这种解析过程都只用 throw,不碰 io,ctfe 用起来省心多了。
从英语翻译·查看原文yeah, enum is fine for a table that never changes. but it forces ctfe, so every path through parseServices has to run at compile time. the smtp 25 line hits your error branch, and stderr.writeln can't run there.
throw an Exception or assert(0, msg) instead. the compiler prints the message as the build error, which is what you want.
ci.sh is separate. ldc2 needs -J. for import(). dub passes that from stringImportPaths, plain ldc2 doesn't.
i keep a parse proc like this with throw only, no io. makes ctfe painless.