```ts
export function fillTemplate(template: string, values: Record<string, string>): string {
  if (typeof template !== 'string') {
    throw new Error('Invalid template: must be a string');
  }

  return template.replace(/{([a-zA-Z0-9_]+)}/g, (match, name) => {
    if (!name || /[^a-zA-Z0-9_]/.test(name)) {
      throw new Error(`Invalid placeholder: ${match}`);
    }
    const value = values[name];
    if (value === undefined) {
      throw new Error(`Missing value for placeholder: ${match}`);
    }
    return value;
  });
}
```