Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 05-23-2025, 09:47 PM   #1
howens
Junior Member
howens began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Mar 2025
Device: Kindle Paperwhite
Exclamation URGENT: Calibre Config Lost + Template Functions Fail (Formatter Expected 'then' in P

Hello Calibre Developers and Community,

I am experiencing an extremely unusual and persistent problem with Calibre on my macOS system, which has progressed from template functions not working to fundamental configuration instability. I've exhausted all standard troubleshooting steps and need your expert assistance. Keep in mind I'm a super noob. I'm banging my head and hands against the wall at this point.

My System Details:

macOS Version: [Sequoia 15.5]
Calibre Version: [8.4.0]
Security Software: None

Full debug log is attached.txt


My primary issue began with Calibre's template language functions consistently failing. For example, a simple custom column using {if(1, '✅', '❌')} or {if(1, 'TRUE', 'FALSE')} would return an error like:
"unknown field if..." or "unknown function if".
Basic field substitutions like {title} do work.

Here is what I have done so far:

Multiple Clean Reinstalls:
Exited Calibre.
Dragged calibre.app to Trash.
Manually deleted any calibre folders found in ~/Library/Application Support/ and ~/Library/Preferences/.
Emptied Trash.
Downloaded a fresh installer from calibre-ebook.com and reinstalled.
Outcome: Problem persisted.

macOS Update:
Updated macOS to the latest available version.
Outcome: No change.

Testing in a New macOS User Account:
Created a completely new, standard macOS user account ("Calibre Test User").
Installed a fresh copy of Calibre in this new account and created a new, empty library.
Initial Outcome: The calibre configuration folder was initially created in the incorrect location (~/Library/Preferences/calibre/) instead of ~/Library/Application Support/calibre/. The template function issue remained.


After that didn't work, I manually deleted calibre folders from both ~/Library/Application Support/ and ~/Library/Preferences/.

Then, I launched Calibre from Terminal using the CALIBRE_CONFIG_DIRECTORY environment variable to explicitly force the correct path: CALIBRE_CONFIG_DIRECTORY="/Users/Calibre Test User/Library/Application Support/calibre" "/Applications/calibre.app/Contents/MacOS/calibre"

Outcome: This successfully created and populated the calibre configuration folder in ~/Library/Application Support/calibre/.

Template Test After This:
A complex template (e.g., {#pages:|Pages: |}{#genre_without_top_level:subitems(0,1)| - |}) then returned "TEMPLATE ERROR Value: unknown field #pages". This told me some parsing was occurring, which seemed like progress to me.
However, when reverting to {if(1, 'SUCCESS', 'FAILURE')}, the error changed to "unknown field if...".

After the above steps, when I tried to restart Calibre normally (not from Terminal via the environment variable), one of two things happened:

The Calibre Startup Wizard appeared, indicating Calibre had completely lost its configuration.
The calibre configuration folder was now present in BOTH ~/Library/Application Support/
AND ~/Library/Preferences/.

Is Calibre confused??

AND THEN when attempting to define a custom Python template function (field_exists) in Preferences → Advanced → Template functions I got this error:

"EXCEPTION: Formatter: if statement: expected 'then', found 'is' near 'mi' on line 2"


Man, maybe all of this is my fault?? I don't actually know but I would be really really grateful for some feedback or help.
Attached Files
File Type: txt full_debug_log.txt (324.2 KB, 8 views)
howens is offline   Reply With Quote
Old 05-23-2025, 11:40 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,242
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
~/Library/Preferences/Calibre is the correct location for calibre configuration files, I suggest you stop trying to change it. If you really do want to change it, then set the environment variable system wide, which admittedly apple makes almost impossible to do on macOS. Read https://manual.calibre-ebook.com/cus...ment-variables

As for your template failing, I dont maintain the template language so cant say off the top of my head but your complex template is likely referring to a column that doesnt exist in your calibre library and your simple template has incorrect syntax.
kovidgoyal is online now   Reply With Quote
Advert
Old 05-24-2025, 04:58 AM   #3
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,358
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
When asking questions about templates it is generally useful to include the templates.

Code:
{if(1, 'SUCCESS', 'FAILURE')}
This is not a valid template in any mode. As I don't know what you are trying to do I can't comment further.

Quote:
AND THEN when attempting to define a custom Python template function (field_exists) in Preferences → Advanced → Template functions I got this error:

"EXCEPTION: Formatter: if statement: expected 'then', found 'is' near 'mi' on line 2"
This says the template is not in Python Template Mode but is instead in General Program Mode. Again, without seeing the template I can't comment further.

EDIT: The calibre template language manual might be useful.

Last edited by chaley; 05-24-2025 at 06:23 AM.
chaley is offline   Reply With Quote
Old 05-24-2025, 04:59 AM   #4
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,358
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Moderator Notice
This thread doesn't belong in the development subforum as you aren't proposing developing anything. Moved to the library subforum.
chaley is offline   Reply With Quote
Old 05-25-2025, 10:05 AM   #5
howens
Junior Member
howens began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Mar 2025
Device: Kindle Paperwhite
Quote:
Originally Posted by kovidgoyal View Post
~/Library/Preferences/Calibre is the correct location for calibre configuration files, I suggest you stop trying to change it. If you really do want to change it, then set the environment variable system wide, which admittedly apple makes almost impossible to do on macOS. Read https://manual.calibre-ebook.com/cus...ment-variables

As for your template failing, I dont maintain the template language so cant say off the top of my head but your complex template is likely referring to a column that doesnt exist in your calibre library and your simple template has incorrect syntax.
Thank you very much. I appreciate both of your responses.
howens is offline   Reply With Quote
Advert
Old 05-25-2025, 11:18 AM   #6
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 79,364
Karma: 145488914
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by howens View Post
Thank you very much. I appreciate both of your responses.
There is a plugin to backup your configuration directory so if you do have a problem, you'll have a backup to go back to.

https://www.mobileread.com/forums/sh...d.php?t=366033
JSWolf is offline   Reply With Quote
Reply

Tags
configuration folder, error, function, parsing


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Template functions: where to find them? Terisa de morgan Library Management 1 09-03-2023 07:05 PM
Template functions not showing return value (calibre 6.5) tamaracks Library Management 4 09-21-2022 11:20 AM
Calibre 6 - problem loading user-defined template functions davidfor Library Management 4 07-12-2022 04:37 AM
Using built-in template functions in a custom template function ilovejedd Library Management 4 01-28-2018 12:20 PM
URGENT HELP!! epub3 template? pluma ePub 3 11-27-2016 06:22 PM


All times are GMT -4. The time now is 11:38 AM.


MobileRead.com is a privately owned, operated and funded community.