use (x as Error) instead of Error(x) for error casting

Error() is an undocumented top-level function that creates a new Error
object.