-
Notifications
You must be signed in to change notification settings - Fork 57
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
chore(postgres): not loading the libpq library by default & better user feedback #2028
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,15 @@ import | |
../../common/databases/db_sqlite, | ||
./sqlite_driver, | ||
./sqlite_driver/migrations as archive_driver_sqlite_migrations, | ||
./queue_driver, | ||
./postgres_driver | ||
./queue_driver | ||
|
||
export | ||
sqlite_driver, | ||
queue_driver, | ||
postgres_driver | ||
queue_driver | ||
|
||
when defined(postgres): | ||
import ./postgres_driver ## This import adds dependency with an external libpq library | ||
export postgres_driver | ||
|
||
proc new*(T: type ArchiveDriver, | ||
url: string, | ||
|
@@ -78,22 +80,33 @@ proc new*(T: type ArchiveDriver, | |
return ok(res.get()) | ||
|
||
of "postgres": | ||
const MaxNumConns = 5 #TODO: we may need to set that from app args (maybe?) | ||
let res = PostgresDriver.new(url, MaxNumConns, onErrAction) | ||
if res.isErr(): | ||
return err("failed to init postgres archive driver: " & res.error) | ||
|
||
let driver = res.get() | ||
|
||
try: | ||
# The table should exist beforehand. | ||
let newTableRes = waitFor driver.createMessageTable() | ||
if newTableRes.isErr(): | ||
return err("error creating table: " & newTableRes.error) | ||
except CatchableError: | ||
return err("exception creating table: " & getCurrentExceptionMsg()) | ||
|
||
return ok(driver) | ||
when defined(postgres): | ||
const MaxNumConns = 5 #TODO: we may need to set that from app args (maybe?) | ||
let res = PostgresDriver.new(url, MaxNumConns, onErrAction) | ||
if res.isErr(): | ||
return err("failed to init postgres archive driver: " & res.error) | ||
|
||
let driver = res.get() | ||
|
||
try: | ||
# The table should exist beforehand. | ||
let newTableRes = waitFor driver.createMessageTable() | ||
if newTableRes.isErr(): | ||
return err("error creating table: " & newTableRes.error) | ||
except CatchableError: | ||
return err("exception creating table: " & getCurrentExceptionMsg()) | ||
|
||
return ok(driver) | ||
|
||
else: | ||
## Error variable to be used if the user is trying to mount Store with a Postgres database | ||
var errPgMsg = "ERROR:" | ||
errPgMsg &= "The POSTGRES flag should be passed to the make command, e.g. " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sounds me that the message is more like targeting developers not node operators. |
||
errPgMsg &= "`make POSTGRES=1 wakunode2`, when setting a postgres " | ||
errPgMsg &= "database as the message archiver. Also, bear in mind that the 'libpq' library " | ||
errPgMsg &= "should be installed beforehand. Hint on how to install it: " | ||
errPgMsg &= "https://docs.waku.org/guides/nwaku/build-source#prerequisites" | ||
return err(errPgMsg) | ||
|
||
else: | ||
debug "setting up in-memory waku archive driver" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, the error message here (i.e. the
builder.nim
) can have no knowledge of the encapsulating application,wakunode2
, ormake
commands, etc. It's good that we're trying to be helpful, but at most the driver knows something like: "Postgres has been configured but not been compiled. Check compiler definitions."I think it's OK to link to the install guide here, even though strictly speaking this module should not even know it's part of nwaku. :)
(Not for this PR, but the correct way to do it is to enumerate the error types here, rather than just returning error strings. That way the application
wakunode2
receives an error result when setting up the archive and the application can then log more instructions as it has the context to do so. For now, this will be overkill.)