better error reporting for unexpected cases