Filing this as a bug, because needlessly unfriendly developer experience should be treated as such.

When a field update attempts to change the field type (which can happen quite often with a Features development workflow), it fails. Drupal could easily say *which* field attempted to change type, but currently doesn't bother.

The attached patch applies against Drupal 7 and likely does not use whatever method of nicely printing variables exception throwing methods should use, and it is only for the error message i needed more info from. But it should show how close at hand we have information we choose not to share with developers.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mradcliffe’s picture

Priority: Normal » Minor

This should follow catch's patch in #792716: More useful field exception message. Changed priority to minor to match as well.

Since that issue is committed and closed, perhaps this one should be changed to fix all Field exceptions instead of just one or two including FieldUpdateForbiddenException (and FieldValidationException?). Tests will also need to be updated.

klausi’s picture

Priority: Minor » Normal
Status: Active » Needs review
FileSize
8.42 KB

Here is a patch that fixes more of the useless exception messages. More messages are now run through t(), don't know if this is wanted. Also promoting the issue to "normal", as this is really an annoyance if you deal with many fields and have to guess which one is broken.

Let's see if and where the test cases need to be corrected.

xjm’s picture

Status: Needs review » Needs work
Issue tags: +Novice

+1 to this. This should make troubleshooting a lot less painful.

Tagging as novice for the task of rerolling the Drupal 8.x patch on account of #22336: Move all core Drupal files under a /core folder to improve usability and upgrades.

If you need help rerolling this patch, you can come to core office hours or ask in #drupal-gitsupport on IRC.

kathyh’s picture

Status: Needs work » Needs review
FileSize
8.48 KB

Update per #3

star-szr’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Tagging for reroll.

dcam’s picture

Status: Needs work » Needs review
FileSize
7.64 KB

Rerolled #4. The changes to list.module were removed. Its FieldUpdateForbiddenException debug message was changed in #1294264: FieldUpdateForbiddenException: Cannot update a list field - better debug info and subsequently migrated to options.module.

jthorson’s picture

#6: field-exceptions-1231710-6.patch queued for re-testing.

jthorson’s picture

Issue tags: -Needs reroll

Updating tags

dcam’s picture

Issue tags: -Novice

#6: field-exceptions-1231710-6.patch queued for re-testing.

dcam’s picture

#6: field-exceptions-1231710-6.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Novice

The last submitted patch, field-exceptions-1231710-6.patch, failed testing.

dcam’s picture

Status: Needs work » Needs review
FileSize
7.55 KB

Rerolled #6.

swentel’s picture

Status: Needs review » Needs work

Most of the exceptions are covered for now, but a still couple are still remaning. Note that we use format_string in exceptions, never t().

Hydra’s picture

Status: Needs work » Needs review
FileSize
2.14 KB

Checked for not covered exceptions and tried to make reasonable changes.

swentel’s picture

+++ b/core/modules/field/lib/Drupal/field/Entity/Field.php
@@ -465,7 +465,7 @@ public function getSchema() {
+        throw new FieldException(format_string('Illegal field type @field_type columns @columns.', array('@field_type' => $this->type, '@columns' => $schema['columns'])));

This will probably not work as columns is an array - field_name should be good enough I think.

Hydra’s picture

Okay, I did the suggested change like discussed in IRC, thx! Thats great :)

martin107’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

3 line patch, is useful and still applies 1 jan 2014.

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Yes these are very annoying when you hit them.

Committed/pushed to 8.x, thanks!

Should be backported.

cs_shadow’s picture

Status: Patch (to be ported) » Needs review
FileSize
1.87 KB

Backported patch in #16 to 7.x.

Status: Needs review » Needs work

The last submitted patch, 19: drupal-1231710-field_exceptions-19.patch, failed testing.

cs_shadow’s picture

Fixed errors for the patch in #19.

cs_shadow’s picture

Status: Needs work » Needs review
mradcliffe’s picture

I know that in Drupal 8 format_string() is the correct function to use, but I am not sure if switching to using format_string() in Drupal 7 is appropriate.

+++ b/modules/field/field.crud.inc
@@ -60,11 +60,12 @@ function field_create_field($field) {
@@ -477,7 +478,7 @@ function field_create_instance($instance) {

@@ -477,7 +478,7 @@ function field_create_instance($instance) {
   }
   // Check that the required properties exists.
   if (empty($instance['entity_type'])) {
-    throw new FieldException(t('Attempt to create an instance of field @field_name without an entity type.', array('@field_name' => $instance['field_name'])));
+    throw new FieldException(format_string('Attempt to create a field @field_name with no entity_type.', array('@field_name' => $field['field_name'])));
   }
   if (empty($instance['bundle'])) {
     throw new FieldException(t('Attempt to create an instance of field @field_name without a bundle.', array('@field_name' => $instance['field_name'])));

The other FieldException in this code snippet still uses the translate function, t().

Should the patch maintain consistency with Drupal 7 or Drupal 8?

cs_shadow’s picture

Attaching patch that uses translate function t(), instead of format_string() to maintain consistency with D7 code.

mradcliffe’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks ready to back port to me.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Needs work
@@ -477,7 +477,7 @@ function field_create_instance($instance) {
   }
   // Check that the required properties exists.
   if (empty($instance['entity_type'])) {
-    throw new FieldException(t('Attempt to create an instance of field @field_name without an entity type.', array('@field_name' => $instance['field_name'])));
+    throw new FieldException(t('Attempt to create a field @field_name with no entity_type.', array('@field_name' => $field['field_name'])));

I don't understand this string change; field_create_instance() creates instances (not fields), so the original one is correct, right?

Regarding the use of t(), I think the current codebase is inconsistent with regard to whether it's used in exception messages (and I'm not sure there is always a right answer). So for this issue I would suggest leaving each as is so as not to rock the boat and risk introducing any strange bugs with the language system + error handling, etc....

So basically, if it uses t() already continue to use it; if it doesn't use t() already but needs placeholders, use format_string().

cs_shadow’s picture

Status: Needs work » Needs review
FileSize
1.23 KB

- Don't recall why I made that string change. Original one surely looks correct. Reverted back to original.

- Used format_string() since originally it wasn't using t() function. Though IMO, use of t() shouldn't break anything because other exception messaged are already using it.

Let me know if we can change it back to t().

filijonka’s picture

Status: Needs review » Reviewed & tested by the community

exceptions should never be translated so there is no reason to use t()

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: drupal-1231710-field_exceptions-27.patch, failed testing.

David_Rothstein’s picture

Status: Needs work » Reviewed & tested by the community
filijonka’s picture

Status: Reviewed & tested by the community » Needs work

well we can't set a patch to rtbc that is failing on tests. probably needs a reroll is my guess but haven't time to check it.

amitgoyal’s picture

Status: Needs work » Needs review

I tested the patch in #27 locally with the test "Search simplify" as it was failing on live. It worked fine for me.

filijonka’s picture

27: drupal-1231710-field_exceptions-27.patch queued for re-testing.

ok so if it works locally let's just do a retest so we know if it is working or not.

filijonka’s picture

Status: Needs review » Reviewed & tested by the community

per #30

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: drupal-1231710-field_exceptions-27.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 27: drupal-1231710-field_exceptions-27.patch, failed testing.

Status: Needs work » Needs review
dcam’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: drupal-1231710-field_exceptions-27.patch, failed testing.

Status: Needs work » Needs review
dcam’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: drupal-1231710-field_exceptions-27.patch, failed testing.

Status: Needs work » Needs review
dcam’s picture

Status: Needs review » Reviewed & tested by the community
David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks!

  • David_Rothstein committed f609f39 on 7.x
    Issue #1231710 by cs_shadow, Hydra, dcam, kathyh, klausi, mlncn: Fixed...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.