Skip to content

Unspecific exception text on unknown type #6910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
speller opened this issue Apr 16, 2025 · 3 comments
Open

Unspecific exception text on unknown type #6910

speller opened this issue Apr 16, 2025 · 3 comments

Comments

@speller
Copy link

speller commented Apr 16, 2025

Bug Report

Q A
Version 4.2.3

Summary

Unspecific exception text on unknown type used in field definition.

Current behavior

Exception message:

Unknown column type "int" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database introspection then you might have forgotten to register all database types for a Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type name is empty you might have a problem with the cache or forgot some mapping information

Expected behavior

Same detailed explanation, but also specifying the erroneous class and field name.

How to reproduce

        #[ORM\Column(type: 'int')]
        public int $foo,
@greg0ire
Copy link
Member

Please provide a stack trace, so it's possible to find the code that throws this exception. Also, you're reporting this on the DBAL repo, but the reproducer uses ORM code. The DBAL does not know about the ORM and therefore cannot provide a class and field name.

@speller
Copy link
Author

speller commented Apr 18, 2025

The stacktrace is the following:

Image

There's no userland code in it. I'm reporting it here because the exception is in the DBAL component.

I think the exception can be handled in the \Doctrine\DBAL\Schema\Table::addColumn() method where both the table and column names are known so they can be added to the exception message and help users identify the error location more quickly. For example, something like this:

Error in table.column: Unknown column type "int" requested. Any Doctrine type that you use...

Maybe something like that code:

    public function addColumn(string $name, string $typeName, array $options = []): Column
    {
        try {
            $column = new Column($name, Type::getType($typeName), $options);
        } catch (\Exception $e) {
            throw new \RuntimeException("Error in {$this->getName()}.{$name}: " . $e->getMessage(), previous: $e);
        }

        $this->_addColumn($column);

        return $column;
    }

@greg0ire
Copy link
Member

Handling it at the DBAL level is a good idea, because it should be good enough for ORM users, and will benefit people that use the DBAL but not the ORM. Please send a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants