roblox-tsr
roblox-ts3mo ago
37 replies
kv_

Proxy error function does not cause unreachable/terminate thread

I have an error/warning function that will print out standardized error codes to make debugging easier:
export const FATAL = (code: ErrorCode) => {
    error('Fatal error occured: ' + code);
};

When I call this, the type solver appears to ignore that this function terminates the running thread:
const some_function = () => {
  FATAL(ErrorCode.FATAL_BAD_SERVER_RESPONSE);
  print('asdfgghjlk') // not marked unreachable
}

const some_function = () => {
  const [ok, data] = // call remote function, if ok = true data is not unknown
  if (!ok) FATAL(...);
  print(data.some_key); // data is of type 'unknown'
}

This function has no condition for calling error(), so calling it should be effectively the same as calling error(), which does work:
const some_function = () => {
  const [ok, data] = // call remote function
  if (!ok) error();
  print(data.some_key); // no error
}
Solution
function FATAL(code: ErrorCode): never {
    error("Fatal error occured: " + code);
}
Was this page helpful?