0

I searched the Laravel docs and stack to see if this was mentioned and found no other mentions.

Is there a way to configure a Laravel application to suppress database warning messages like the attached from displaying?

This specific error shows that the spatie/laravel-activitylog app is logging a change that is getting truncated. The 'properties' field in question is of type: TEXT.

error message

Putting a try/catch around the initial transaction (the edit itself) doesn't trap the error message.

Thoughts?

If any specific code snippets would be helpful, let me know and I'll update this post.

apokryfos
  • 38,771
  • 9
  • 70
  • 114
Phil
  • 320
  • 4
  • 16
  • 1
    how about fixing, rather than trying to hide errors –  Mar 11 '19 at 22:17
  • This error, thrown by the logging package, is the only thing 'broken' here and it is not my package. The actual update of my model's table happens with the very long base64 string. The activity_log table also gets the truncated line written as well so, except for the hard failure, nothing seems to be failing. – Phil Mar 12 '19 at 04:17
  • what does that matter, suppressing errors instead of fixing them is poor practice. –  Mar 12 '19 at 04:31

4 Answers4

0

Unfortunately I am not familiar with this package. However a quick scan on their Github tells me it looks a model, that can be set in the config, is being used to store this data to the database.

A suggestion would be to make use of the Eloquent events, saving in particular since this will be triggered when creating and updating.

In the callback function of this event you could truncate specific attributes of the model. In this case that would be the properties attribute if I am not mistaking.

It looks like you are trying to store some base64 strings and a guess would be that this is causing the problem. Maybe you can make a regular expression on the contents of properties and replace all src="somereallylongbase64" with src="...base64..." to prevent large important parts of data to go missing with a simple global tuncate of properties.

Thomas Van der Veen
  • 3,136
  • 2
  • 21
  • 36
0

Thats not a warning is it? It's an exception because your insert statement is trying to insert to much data in the "properties" column.

You probably don't want to suppress that type of message (and probably not possible to suppress the underlying error), you need to fix it by making the column fit more data or use some other saving mechanism if it's a lot of data you are saving.

martinethyl
  • 184
  • 1
  • 12
0

Hey sorry for being late to the party. To suppress truncation warnings just throw it in a CAST.

Examples:

-- With decimal(4, 1) (too many decimal places throws a warning but doesn't throw an
-- exception unlike having too high a number would):
INSERT INTO sysmon.temperatures VALUE (NOW(), CAST(46594/1000 AS DECIMAL(4,1)), 36.5);
-- Mysql: Process run is green!

-- With VARCHAR(400) (when too many characters throws a warning before truncating):
INSERT INTO website.blog_comments VALUE (NOW(), CAST('some really long string' AS VARCHAR(400)));
-- Mysql: You're the boss!

TEXT would work similarly to the VARCHAR example above.

Darren S
  • 516
  • 4
  • 8
0

spatie/laravel-activitylog uses your model $fillable attributes to know what attributes to log and log them under the properties column of activity_log table.

Detect what attribute is going to get truncated in MySQL and include it to the $logAttributesToIgnore property in your model:

public static $logAttributesToIgnore = [];

If you insist that you log the attribute, you should create a migration and change the properties column from TEXT to MEDIUMTEXT or bigger.

Welder Lourenço
  • 994
  • 9
  • 12